#23655 [NEW]: foreach for file() dont work

From: Date: Fri, 16 May 2003 08:15:10 +0000
Subject: #23655 [NEW]: foreach for file() dont work
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-39770@lists.php.net to get a copy of this message
From:             edo at domis dot de
Operating system: Windows 98
PHP version:      4.3.1
PHP Bug Type:     Filesystem function related
Bug description:  foreach for file() dont work

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 bug report at http://bugs.php.net/?id=23655&edit=1
-- 
Try a CVS snapshot:         http://bugs.php.net/fix.php?id=23655&r=trysnapshot
Fixed in CVS:               http://bugs.php.net/fix.php?id=23655&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=23655&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=23655&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=23655&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=23655&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=23655&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=23655&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=23655&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=23655&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=23655&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=23655&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=23655&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=23655&r=gnused



Thread (2 messages)

« previous php.bugs (#39770) next »