| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2011-01-29 00:31 UTC] rosshowatson at gmail dot com
 Description:
------------
If reading a file that contains "<?" this is ignored and any text afterwards on that line is ignored.
<?php - does not read
<? php - does not read
<?<?
Even with extra spaces before the <? gets shifted to the next line.
The fgetc reads the line and can show the data but lines read with the file() command ignores the line.
Test script:
---------------
Two files required:  phpinfo2.php
<?php - does not read
phpinfo();
<?
< ?
<?php - does not read
<? php - does not read
?>
Second file:  readFileViaPHP.php
<?
$lines = file('phpinfo2.php',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
echo '<pre>';
print_r ($lines);
echo '</pre>';
echo  '<br />' . "\n";
?>
Expected result:
----------------
You should see all records from phpinfo2.php
Array
(
    [0] =>   <?php - does not read
    [1] =>   phpinfo();
    [2] =>   <?
    [3] =>   < ?
    [4] =>   <?php - does not read
    [5] =>   <? php - does not read
    [6] =>   ?>
)
Actual result:
--------------
Array
(
    [0] =>   phpinfo();
    [2] =>    < ?
    [5] =>    ?>
)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 12:00:01 2025 UTC | 
It's be interpreted as HTML tags, hence why it goes 0, 2, 5. add header('Content-Type: text/plain'); to the top or click view source.I have tried adding the header('Content-Type: text/plain'); statement to both the main PHP program and the source that it is reading but get the same results. I have taken the phpinfo2.php file and renamed this to phpinfo.txt with the same result. Just now I decided to examine the HTML source code and it does DOES SHOW THE CODE correctly. THE BUG IS NOT IN PHP. THE BUG IS IN IE8. In Opera it works correctly. The cause is Micr0$0ft. The data is in what is sent to the browser, the browser fails to read the HTML correctly and drops lines here there and everywhere. Work around for IE8 only: $lines = file('phpinfo2.txt',FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); $lines = str_replace("<", "<", $lines); // replace the < with < Close the problem/bug as no fix required.