|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53875 file() fgets() fgetc() will read <?php but not save this
Submitted: 2011-01-29 00:31 UTC Modified: 2011-01-29 05:12 UTC
From: rosshowatson at gmail dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.3.5 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: rosshowatson at gmail dot com
New email:
PHP Version: OS:


 [2011-01-29 00:31 UTC] rosshowatson at gmail dot com
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
< ?
<?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

    [0] =>   <?php - does not read
    [1] =>   phpinfo();
    [2] =>   <?
    [3] =>   < ?
    [4] =>   <?php - does not read
    [5] =>   <? php - does not read
    [6] =>   ?>

Actual result:
    [0] =>   phpinfo();
    [2] =>    < ?
    [5] =>    ?>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-29 01:11 UTC]
-Status: Open +Status: Bogus
 [2011-01-29 01:11 UTC]
It's be interpreted as HTML tags, hence why it goes 0, 2, 5.

header('Content-Type: text/plain'); to the top or click view source.
 [2011-01-29 05:12 UTC] rosshowatson at gmail dot com
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("<", "&lt;", $lines);  // replace the < with &lt;

Close the problem/bug as no fix required.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 25 00:01:31 2024 UTC