php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #23655 foreach for file() dont work
Submitted: 2003-05-16 03:15 UTC Modified: 2003-05-16 03:27 UTC
From: edo at domis dot de Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 4.3.1 OS: Windows 98
Private report: No CVE-ID: None
 [2003-05-16 03:15 UTC] edo at domis dot de
Iterating with "foreach" thru an array created by the "file()" function dont work on Windows 98 (Linux work!) as expected. Using a barebone forach fails while the the Example from the documentation works.

I made this example code for testing pupose. Save the code in a free named file. The code will load the contents of it self and iterate thru the lines two times.
The first time will fail, the second time the example of the documentation is used the $line ist wrapped by the htmlspecialchars($line) function. On my test approaches I wrote the data with a "fwrite" function, this also works!
It has to do with a unwrapped "echo $line", but a self made wrapper also dont worked.

<?php
  //Get this filename
  $fnthis = getcwd().$_SERVER['PHP_SELF'];
  // Read the actual data from the file
  echo "Try to read $fnthis<br>";
  $lines = file ($fnthis);
  echo "Loop work not under Windows98, but under *nix and 4.3.1! Start<br>\n";
  // Iterate thru lines
  foreach ($lines as $line) {
    echo ":: $line <br>\n";
  }
  echo "Loop work not under Windows98, but under *nix and 4.3.1! End<br><br>\n";
  echo "Loop work! Start<br>\n";
  // Iterate thru lines
  foreach ($lines as $line) {
    echo ":: ".htmlspecialchars($line) . "<br>\n";
  }
  echo "Loop work! End<br>\nThe difference ist the function 'htmlspecialchar' call<br>\n";
  // phpinfo, if needed
  phpinfo();
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-05-16 03:27 UTC] edo at domis dot de
Every time the same old story: Seeking hours give up, and five minutes later found!
I am very sorry about this "non-bug" reporting.
A view to the "raw" output of the program would prevent such a mistake.
Sorry again.
Ekkehard
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 01 01:01:28 2024 UTC