PHP Advanced Questions and Answers part one

PHP Advanced Questions and Answers part one :


1.Is it possible to set a time expire page in PHP.?

Yes it is

Using header(“Expires: fri, 07 mar 2007 05:00:00 GMT”);

<?php
header(“Expires: fri, 07 mar 2007 05:00:00 GMT”);
?>

2.How can we SAVE an image from a remote
web Server to my web server using PHP?

<?php
$file_rimg = fopen(“http://w3answers /image23.jpg”,’rb’);
$newfile_name_img = “/tmp/tutorial.file”;
$file_wnew = fopen($newfile_name_img,’wb’);
while (!feof($file_rimg)) {
$chunk_rd = fread($file_rimg,1024);
fwrite($file_wnew,$chunk_rd);
}
fclose($file_wnew);
fclose(file_rimg);
?>
3.What is the output of 2^2 in php ?

The answer is 0 (Zero)
Important note
Everyone expected answer would be 4.   But answer is zero.  How it happened only in php ?

The ^ operator is different in each language.In PHP ^ means the bitwise exlusive or of the two numbers.

4.What is the output of below script?

<?php
$x = 3;
switch ($x) {
case 2: echo ‘line 1’; break;
case 3:
case 4: echo ‘line 2’; break;
default: echo ‘line 3’;
}
?>

a. echo ‘line 3’;
b. echo ‘line 2’;
c. Error
d. None of the above

Ans: b (Answer is line2)
5.What is the output here?

<?php
$x = ‘raj’;
echo ‘Hello $x’;

?>

a. helloravj
b. Parse error
c. hello $x
d. syntax error

ANS: c

6.What output do you get here?

<?php
$list = array(“block”,”cut”,”pens”,”dogs”);
$list[] = “elephant”;
$list[] = “dragon”;
print “$list[4]”;
?>

a. Error
b. elephant
c. dragon
d. nothing
e. dogs

ANS: b (elephant)

7.what is the output for following code?

<?php
echo 12+FALSE;
?>

a. 12
b. no
c. parse error
d. T_ECHO error
e. FALSE

ANS: 12

8.What is the output ?

<?php
$x=7;
if ($x < 2) { echo “11”; }
elseif ($x < 16) { echo “12”; }
elseif ($x < 14) { echo “13”; }
elseif ($x > 14) { echo “14”; }
elseif ($x < 10) { echo “15”; }
else { echo “16”; }

?>

a.16
b.15
c.12
d.13

ANS:12

9.What is the result here?

<?php
echo “test”;
$x = ”;
switch ($x) {
case “0”: echo “String”; br;
case 0: echo “”; break;
case NULL: echo “NULL”; br;
case FALSE: echo “integer”; br;
case “”: echo “no string”; br;
default: echo “nothing else”; br;
}

?>

a. Something else
b. Empty string
c. Integer
d. String

ANS: Integer

10.What is the output?

<?php
function x ($y) {
function y ($z) {
return ($z*2); }
return($y+3); }
$y = 4;
$y = x($y)*y($y);
echo “$y”;
?>

a. None
b. 54
c. 56
d. 58

ANS:56

 

source: w3answers.com

5 thoughts on “PHP Advanced Questions and Answers part one”

Leave a Reply

Your email address will not be published. Required fields are marked *

19 − 8 =