开发者

File & file_get_contents bugging on reading simple file

file or file_get_contents do not read this sample file properly

<?php

?>

This is the test program

$flines=file('../include/test.php');  
echo '<pre>';  
print_r($flines);  
echo '</pre>';  
for($i=0;$i<count($flines);$i++) {  
    echo("$i:".$flines[$i]."\n<br>");
}  
echo "File Get Contents";  
echo(file_get_contents('../include/test.php'));  

This is the output

Array (

[0] => ?>

)

0:1:?>

File Get Contents

Basically it skips the php declaration for some reason... and the file开发者_Go百科 is empty

addition every works fine when removing the opening < of course


You didn't trick php, php was right all along; you tricked yourself....

$flines=file('./x.php');
echo '<pre>';
print_r(array_map('htmlentities',$flines));
echo '</pre>';
for($i=0;$i<count($flines);$i++) {
    echo("$i:".htmlentities($flines[$i])."\n<br>");
}
echo "File Get Contents";
echo(htmlentities(file_get_contents('./x.php')));

Think about what a web browser does when it encounters < rather than <

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜