I've created a script to parse through a data file which contains coma separated fields of data. The script works on Apache, however when I run it on under Windows (running PHP as a CGI) the script produces an Undefined offset notice. What is strange about this notice is that the line of code which contains the array element never gets executed.
Here is what I have: A data file containing: === START OF FILE ===== 1,01545,"01612,01545,01505,01609,01606,01562" === END OF FILE ===== 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? This script works fine under Apache. I haven't a clue what is going on. Comments welcome, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php