php.net |  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
 [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] =>    ?>
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-29 01:11 UTC] scottmac@php.net
-Status: Open +Status: Bogus
 [2011-01-29 01:11 UTC] scottmac@php.net
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.
 [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 Dec 07 22:01:27 2024 UTC