|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2003-05-16 03:27 UTC] edo at domis dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 00:00:02 2025 UTC |
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(); ?>