Chris Williams wrote:
The first and last lines contain carriage returns. The second or middle line
contains sample data.

The script that reads and parses the data is:

  $countLines = fopen("data.txt", "r");
  while (!feof($countLines))
  {
   $newLine = fgets($countLines, 1024);
   echo "line length:  " . strlen($newLine) . "<br>";
   if(strlen($newLine) > 0)
   {
   $newLine = ereg_replace ("\"", "", $newLine);
   $zip_forward = explode(",",$newLine);
   $location_id = trim($zip_forward[0]);
   echo "array size: " . count($zip_forward) . "  ID: $location_id<br>";
   $zip_to = trim(substr($zip_forward[1], 0, 5));
   }
  }
  fclose($countLines);

What's odd here is that the last line, which has a length of 0, should never
cause the if(strlen($newLine) > 0) to execute the lines of script contained
within the if conditional. And in fact the lines DON'T get executed.
However, on the Windows server I get the following error
PHP Notice: Undefined offset: 1 in \debug.php on line 20. This points to my
code that evaluates the second element of the array $zip_to =
trim(substr($zip_forward[1], 0, 5));

If I never evaluate the $zip_forward[1] array element within the if
conditional, why would PHP test the array $zip_forward for the proper number
of elements?

Okay, if you're getting that NOTICE then the line of code is executing. So even though you think the strlen() line is failing, it's not.


Anyhow, the whole issue here is just that your two servers have different error_reporting() levels. One is set to show NOTICES while the other is not. If you use @trim(...), you can suppress this warning.

The code is running the same on both servers, though...

--
---John Holmes...

Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals – www.phparch.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to