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
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: edo at domis dot de
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 02:01:29 2024 UTC