Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined offset notice

Status
Not open for further replies.

inusrat

Programmer
Feb 28, 2004
308
0
0
CA
I am geting the following message

Notice: Undefined offset: 1 in C:\Inetpub\ on line 69

where line 69 is
list($key,$val) = explode("=", $lines[$i]);

Here is the code

*************
if (strcmp ($lines[0], "SUCCESS") == 0) {

for ($i=1; $i<count($lines);$i++){
list($key,$val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
*************

 
Dump your $lines array. How many lines are in it when you get the message?
Code:
echo '<pre>';print_r($lines);echo '</pre>',"\n";

Ken
 
If I had to guess, it's that one of the elements of $line does not have an "=" in it, so there is no second value to insert into $val.

Here is my code:
Code:
<?php

$foo = 'a=3';
$bar = 'a';

list ($a,$b) = explode ("=", $foo);

list ($a,$b) = explode ("=", $bar);

?>

Which returns:

PHP Notice: Undefined offset: 1 in /path/to/test_list.php on line 8

Line 8 is the line which tries to use list and explode with a value that has no equals sign in it.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I forgot to mention that this is tested paypal's code and works fine on their server, i checked myself and gives no such offset notice. It might have something to do with my php setting at home server, but I do not know what.

when I put
echo '<pre>';print_r($lines);echo '</pre>',"\n";
with in the for loop I got


Array
(
[0] => SUCCESS
[1] => mc_gross=2.00
[2] => address_status=confirmed
[3] => tax=0.00
[4] => paypal_address_id=EWYG8S34DG2XW
[5] => payer_id=KAQZQUNR63J4U
[6] => address_street=79+thorny+vineway
[7] => payment_date=13%3A35%3A55+Dec+13%2C+2004+PST
[8] => payment_status=Completed
[9] => address_zip=m2j4j3
[10] => first_name=irfan
[11] => mc_fee=0.61
[12] => address_name=irfan+customer
[13] => custom=
[14] => payer_status=verified
[15] => business=irfan_n34%40yahoo.com
[16] => address_country=Canada
[17] => address_city=north+York
[18] => quantity=1
[19] => payer_email=matrimonial1%40786marriage.com
[20] => txn_id=2AC28239FH421633D
[21] => payment_type=instant
[22] => last_name=customer
[23] => address_state=Ontario
[24] => receiver_email=irfan_n34%40yahoo.com
[25] => address_owner=1
[26] => payment_fee=
[27] => receiver_id=KAV6BVB652366
[28] => ebay_address_id=
[29] => txn_type=web_accept
[30] => item_name=crush
[31] => mc_currency=CAD
[32] => item_number=01
[33] => residence_country=CA
[34] => payment_gross=
[35] =>
)





 
There is a forum on the Paypal developers area. Find it and ask you question there. Someone may be able to tell you a better answer.

 
If this works on the paypal server without any error-messages that means they suppress the 'notices', as notices are non-critical errormessages.

You could suppress notices yourself, have a look at
However it is better to actually check that an entry has an = before exploding and assigning it. I guess you want to ignore the lines without =.

This should work I think

Code:
if (strcmp ($lines[0], "SUCCESS") == 0) {

for ($i=1; $i<count($lines);$i++)
{
    if (strpos($lines[$i], '=') !== false)
    {
        list($key,$val) = explode("=", $lines[$i]);
        $keyarray[urldecode($key)] = urldecode($val);
    }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top