Re: [PHP] Undefined offset on Windows not on Apache?
From: Chris Williams (chris_at_escaperadius.com)
Date: 11/30/03
- Next message: Narayanan: "How to see the table structure"
- Previous message: Leslie: "PHP sendmail_path problem"
- In reply to: John W. Holmes: "Re: [PHP] Undefined offset on Windows not on Apache?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
To: php-general@lists.php.net Date: Sun, 30 Nov 2003 13:32:39 -0800
I don't believe the disputed line of script is being executed because just
before that line I include the following print statement,
echo "array size: " . count($zip_forward) . " ID: $location_id<br>";
which does not get executed when my conditional fails.
Right you are on the error reporting, I included error_reporting (E_ALL); in
my test script and can reproduce same error on Apache.
Chris
"John W. Holmes" <holmes072000@charter.net> wrote in message
news:3FCA2F4C.3090206@charter.net...
> 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
- Next message: Narayanan: "How to see the table structure"
- Previous message: Leslie: "PHP sendmail_path problem"
- In reply to: John W. Holmes: "Re: [PHP] Undefined offset on Windows not on Apache?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|