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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
46 + 6 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2020 The PHP Group
All rights reserved.
Last updated: Mon Oct 26 02:01:23 2020 UTC