#23655 [Opn->Bgs]: foreach for file() dont work
ID: 23655
User updated by: edo at domis dot de
Reported By: edo at domis dot de
-Status: Open
+Status: Bogus
Bug Type: Filesystem function related
Operating System: Windows 98
PHP Version: 4.3.1
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2003-05-16 03:15:10] 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();
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=23655&edit=1
Thread (2 messages)