开发者

Interviewer - I will not repeat the question so be careful. How to print all the text (All) of a php file as written within it?

Yesterday I went for a php Interview and interviewer just asked me one question,

After i开发者_如何学Cntroducing himself

Interviewer - I will not repeat my first and last question so be careful. How to print all the text ( All ) of a php file as coded within it ?

What I answered- I tried to answer it by telling the interviewer that I will write the whole code in <code><?php ?></code> tag, thats what I could think of at that time.

Interviewer - Are you sure !

I didnt replied.

Interviewer - Thanks you (unsatisfied facial expression)

and guess I was not selected. I googled for it also asked it to my friends but I didnt got the answer.

Can anyone answer it.

Please Please.Please. I want to know the answer.

Thanks to interviewer he gave me good question to ask on SO


echo "<pre>";
echo htmlentities(file_get_contents($_SERVER['PHP_SELF']));
echo "</pre>";

This will get the name of the file we are in grab the contents of it and then display it on the page as written.


I think interviewer was referring to the highlight_file function.


<?php echo file_get_contents(__FILE__); ?>

This is the most basic answer that satisfies what the interviewer asked. I would follow up with a clarifying question as to whether they wanted a prettier display.


Access the appropriate item in $_SERVER to find out the current script name, then use PHP's file functions to display the contents of the file.


this is the nicer way

echo highlight_string(file_get_contents($_SERVER['SCRIPT_FILENAME']));


<?php
    $file = new SplFileObject( __FILE__ );
    $file->fpassthru();
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜