PHP Slips Solution
PHP Slips Solution
Q1
<?php
phpinfo();
?>
Q2_1
<html>
<body>
</form>
<?php
function count_vowels($str){
$cnt_vowels = 0;
if(key_exists($str[$c],$vowels)){
$cnt_vowels += 1;
$vowels[$str[$c]] += 1;
if(isset($_POST['submit'])){
$str = $_POST['str'];
count_vowels($str);
?>
</body>
</html>
Q2_2
<?php
$arr1 = array("a"=>1,"b"=>2);
$arr2 = array("c"=>3,"b"=>4,"a"=>1);
?>
<br>
</form>
<?php
if(isset($_POST["submit"])){
$ope = $_POST['select'];
switch($ope){
case 'Merge':
$res = array_merge($arr1,$arr2);
break;
case 'Inter':
$res = array_intersect_assoc($arr1,$arr2);
break;
case 'Union':
$res = array_merge($arr1,$arr2);
break;
$res = array_diff_assoc($arr1,$arr2);
break;
print_r($res);
?>
SLIP 2
Q1
<?php
$id = 101;
$name = "Rahul";
$age = 20;
$add = "Pune";
?>
Q2_1
<?php
switch($ope){
case '+':
case '*':
case '/':
if(isset($_POST["submit"])){
$n1 = $_POST["n1"];
$n2 = $_POST["n2"];
$ope = $_POST["ope"];
$res = calc($n1,$n2,$ope);
?>
SLIP 3
Q2_1
<h2>Bill Details</h2>
<form method="post">
<table>
<tr>
<th>Item Code</th>
<th>Item Name</th>
<th>Units Sold</th>
<th>Rate</th>
</tr>
<?php
for ($i=1; $i<=5; $i++) {
echo "<tr>";
echo "</tr>";
?>
</table>
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$items = $_POST['item'];
echo "<h2>Bill</h2>";
echo "<table>";
$code = $item['code'];
$name = $item['name'];
$units = $item['units'];
$rate = $item['rate'];
echo "<tr>";
echo "<td>$code</td><td>$name</td><td>$units</td><td>$rate</td><td>$total</td>";
echo "</tr>";
echo "</table>";
?>
SLIP 4
Q1
<?php
$n1 = 10;
$n2 = 20;
$n3 = 30;
?>
Q2_1
<br>
<br>
</form>
<?php
if(isset($_POST["submit"])){
$str1 = $_POST["s1"];
$str2 = $_POST["s2"];
$ope = $_POST['select'];
if($ope == '1'){
if($str1 == $str2){
else{
if(strcmp($str1,$str2)==0){
echo "<br>The first string is less than the second string using 'strcmp' function";
else {
echo "<br>The first string is greater than the second string using 'strcmp' function";
$string = $str1.$str2;
?>
Q2_2
<html>
<head>
<script>
function readTextFile() {
xhr.onreadystatechange = function() {
document.getElementById('output').innerHTML =
xhr.responseText;
xhr.open('GET', 'a.txt');
xhr.send();
</script>
</head>
<body>
<div id="output"></div>
</body>
</html>
SLIP 5
Q1
<?php
$num = 153;
$temp = $num;
$sum = 0;
$power = strlen($temp);
$rem = $temp%10;
$sum += pow($rem,$power);
$temp /= 10;
if($sum == $num){
else{
?>
Q2_1
<br><br>
</form>
<?php
if(isset($_POST["submit"])){
$select = $_POST["select"];
switch($select){
case '1':
print_r($arr);
break;
case '2':
echo sizeof($arr);
break;
?>
Q2_2
<?php
class Myclass{
};
foreach($properties as $key=>$value){
$methods = get_class_methods(get_class($obj));
foreach($methods as $m){
if(property_exists($obj,'property1')){
if(method_exists($obj,'method1')){
?>
SLIP 6
Q1
<br><br>
</form>
<?php
function isPrime($num){
if($num<2){
return False;
for($i=2;$i<$num;$i++){
if($num%$i == 0){
return False;
return True;
if(isset($_POST["submit"])){
$num = $_POST["num"];
if(isPrime($num)){
else{
?>
Q2_1
<?php
print_r($arr);
?>
</form>
<?php
if(isset($_POST["submit"])){
$select = $_POST["select"];
switch($select){
case '1':
print_r(array_flip($arr));
break;
case '2':
shuffle($arr);
print_r($arr);
break;
?>
SLIP 7
Q1
<br><br>
</form>
<?php
function reverse($str){
return strrev($str);
if(isset($_POST["submit"])){
$str = $_POST["str"];
$newString = reverse($str);
echo "$newString";
?>
Q2_1
<?php
$reversedArray = array_reverse($arr);
print_r($reversedArray);
?>
SLIP 8
Q1
<br><br>
</form>
<?php
function isPalindrome($str){
if($str == strrev($str)){
return True;
return False;
}
if(isset($_POST["submit"])){
$str = $_POST["str"];
if(isPalindrome($str)){
else{
?>
Q2_1
<?php
$fruits = array(
"green" => 5,
"yellow" => 3
),
"navel" => 8,
"valencia" => 12
),
"red" => 2
);
print_r($fruits);
?>
SLIP 0
Q1
<?php
$num=1;
$num++;
echo "<br>";
?>
Q2_1
<br><br>
</form>
<?php
session_start();
if(!isset($_SESSION['stack_array'])){
$_SESSION['stack_array'] = array();
$s = array();
}
else{
$s = $_SESSION['stack_array'];
if(isset($_POST["submit"])){
$ope = $_POST["select"];
switch($ope){
case 'insert':
$ele = $_POST["ele"];
array_push($s,$ele);
break;
case 'delete':
if(empty($s)){
else{
array_pop($s);
foreach($s as $ele){
$_SESSION['stack_array'] = $s;
}
?>
SLIP 10
Q1
<?php
echo show_source("temp.html");
?>
Q2_1
<br><br>
</form>
<?php
session_start();
if(!$_SESSION['queue']){
$q = array();
else{
$q = $_SESSION['queue'];
if(isset($_POST['submit'])){
$ope = $_POST['select'];
switch($ope){
case 'insert':
$ele = $_POST['ele'];
array_push($q,$ele);
echo "$ele inserted in queue..!!";
break;
case 'delete':
if(empty($q)){
break;
array_shift($q);
break;
case 'display':
if(empty($q)){
break;
foreach($q as $i){
$_SESSION['queue'] = $q;
?>
Temp
<html>
<h1>Hey There..!!</h1>
</html>
SLIP 11
Q2_1
<html>
<body>
</form>
<?php
function count_vowels($str){
$cnt_vowels = 0;
if(key_exists($str[$c],$vowels)){
$cnt_vowels += 1;
$vowels[$str[$c]] += 1;
if(isset($_POST['submit'])){
$str = $_POST['str'];
count_vowels($str);
?>
</body>
</html>
SLIP 14
Q2_1
<br>
<br>
</form>
<?php
if(isset($_POST["submit"])){
$str1 = $_POST["s1"];
$str2 = $_POST["s2"];
$ope = $_POST['select'];
if($ope == '1'){
if($str1 == $str2){
else{
if(strcmp($str1,$str2)==0){
else {
echo "<br>The first string is greater than the second string using 'strcmp' function";
$string = $str1.$str2;
$pos = $_POST['pos'];
?>
SLIP 15
Q2_2
<?php
class Myclass{
};
$properties = get_object_vars($obj);
foreach($properties as $key=>$value){
$methods = get_class_methods(get_class($obj));
foreach($methods as $m){
if(property_exists($obj,'property1')){
if(method_exists($obj,'method1')){
?>
SLIP 18
Q2_2
<br><br>
</form>
<?php
if(isset($_POST["submit"])){
$oname = $_POST["oname"];
$res = pg_query($db,$sql);
while($row = pg_fetch_row($res)){
echo "</table>";
pg_close($db);
?>
SLIP 10
Q1
<?php
$num = 65;
$alphabet = chr($num);
echo "<br>";
?>