zang8027 Posted February 19, 2009 Share Posted February 19, 2009 I am a little confused here. I have a cart that submits items to paypal, then paypal sends back a serialized URL to my page with the information. So if i use $_GET['item_name1'], it gives me what ever item one is. If i change it to item_name2, if there is a 2, it gives me that name. Same with quantity. Now, i need a way to say, get ALL the params that are sent back, (its in a array thats serialized so i would need $key => $value) but I am not quite sure on how to do this. Here is the code that paypal generated for me.. <?php ....... // parse the data $lines = explode("\n", $res); $keyarray = array(); if (strcmp ($lines[0], "SUCCESS") == 0) { for ($i=1; $i<count($lines);$i++){ list($key,$val) = explode("=", $lines[$i]); $keyarray[urldecode($key)] = urldecode($val); } // check the payment_status is Completed // check that txn_id has not been previously processed // check that receiver_email is your Primary PayPal email // check that payment_amount/payment_currency are correct // process payment $itemname2 = $keyarray['item_name2']; $amount = $keyarray['mc_gross']; $quantity2 = $keyarray['quantity2']; echo ("<p><h3>Thank you for your purchase!</h3></p>"); echo ("<b>Payment Details</b><br>\n"); echo ("<li>Name: $userSession</li>\n"); echo ("<li>Item: $itemname2</li>\n"); echo ("<li>Amount: $amount</li>\n"); echo ("<li>quantity: $quantity2</li>\n"); echo ("<li>Restaurant: $restaurantSession</li>\n"); } else if (strcmp ($lines[0], "FAIL") == 0) { // log for manual investigation } } fclose ($fp); ?> Now, pretty much, how can i use a for each to grab each value thats being sent back for quantity and item name. i want my page to print out: Pep. pizza (item1) 1(quantity1) cheese pizza (item2) 4(quantity2) does not need to be formatted, just echo'd Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/ Share on other sites More sharing options...
zang8027 Posted February 19, 2009 Author Share Posted February 19, 2009 how would i use a foreach to get post or get values? maybe thats simpler Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766515 Share on other sites More sharing options...
premiso Posted February 19, 2009 Share Posted February 19, 2009 foreach ($_POST as $key => $val) { echo $key . " => " . $val . "<br />"; } Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766529 Share on other sites More sharing options...
zang8027 Posted February 19, 2009 Author Share Posted February 19, 2009 ok thank you.. that got me somewhere.. but not what i need.. any ideas how i can just pull out item_name_(however many) and quantity? im getting EVERYTHING thats posted back.. is there like a php command kind of like the mySQL command "LIKE" that i can just pull out item names haha Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766553 Share on other sites More sharing options...
sasa Posted February 19, 2009 Share Posted February 19, 2009 can you post example of data that you want to parse Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766554 Share on other sites More sharing options...
zang8027 Posted February 19, 2009 Author Share Posted February 19, 2009 here is what i get when i just pull everything from the url (which is encoded in an array) mc_gross = 56.24 protection_eligibility = Eligible address_status = confirmed item_number1 = tax = 0.00 item_number2 = payer_id = H6RLXPBW3ZDW6 item_number3 = address_street = 1 Main St payment_date = 13:16:18 Feb 19, 2009 PST payment_status = Completed charset = windows-1252 address_zip = 95131 mc_shipping = 5.44 mc_handling = 0.00 first_name = Test mc_fee = 1.93 address_country_code = US address_name = Test User custom = 3 payer_status = verified business = sss_1233964440_biz@zoominternet.net address_country = United States num_cart_items = 3 mc_handling1 = 0.00 mc_handling2 = 0.00 mc_handling3 = 0.00 address_city = San Jose payer_email = bbb_1233964418_per@zoominternet.net mc_shipping1 = 5.44 mc_shipping2 = 0.00 mc_shipping3 = 0.00 txn_id = 9M838033K29070309 payment_type = instant last_name = User address_state = CA item_name1 = Medium Sausage Pizza receiver_email = sss_1233964440_biz@zoominternet.net item_name2 = Medium Ham and Pinnapple Pizza payment_fee = 1.93 item_name3 = Medium Ham and Cheddar Pizza quantity1 = 1 quantity2 = 2 receiver_id = THLEVDLL2GVXE quantity3 = 5 txn_type = cart mc_gross_1 = 11.79 mc_currency = USD mc_gross_2 = 12.70 mc_gross_3 = 31.75 residence_country = US transaction_subject = 3 payment_gross = 56.24 i want this: item_name1 = Medium Sausage Pizza item_name2 = Medium Ham and Pinnapple Pizza item_name3 = Medium Ham and Cheddar Pizza Same with quantity because i am sending this via fax or email and I dont really want EVERYTHING sent.. unless i have too Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766558 Share on other sites More sharing options...
premiso Posted February 19, 2009 Share Posted February 19, 2009 What is the "actual" string that get's returned? And can you convert it to an array on your own? Show us the raw text, at least the item portion of the raw text that is returned. Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766571 Share on other sites More sharing options...
zang8027 Posted February 19, 2009 Author Share Posted February 19, 2009 http://www.clikndine.com/html/paypalipn.php?tx=23E589806T3556725&st=Completed&amt=56.24&cc=USD&cm=3&item_number=&sig=rAYIra87aa60F6XWoaDWd%2fm3kGSzctJy%2bsp9YEWcvrXr2ae4Ur81BsL8pSmHlI7QKw2XK6ysmDZL%2f%2bN1CfDjpHaJu5Y1Sq91K5g0%2bKZ6YHTIM1gb9znSaOG8YFp7iSZiTNEImOdCzvNtPukPBBnypCa3EmotuJ66gpoosTAyO3c%3d Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766589 Share on other sites More sharing options...
premiso Posted February 19, 2009 Share Posted February 19, 2009 parse_str "may" help given that it is a string returned Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766592 Share on other sites More sharing options...
sasa Posted February 19, 2009 Share Posted February 19, 2009 try <?php $test = 'mc_gross = 56.24 protection_eligibility = Eligible address_status = confirmed item_number1 = tax = 0.00 item_number2 = payer_id = H6RLXPBW3ZDW6 item_number3 = address_street = 1 Main St payment_date = 13:16:18 Feb 19, 2009 PST payment_status = Completed charset = windows-1252 address_zip = 95131 mc_shipping = 5.44 mc_handling = 0.00 first_name = Test mc_fee = 1.93 address_country_code = US address_name = Test User custom = 3 payer_status = verified business = sss_1233964440_biz@zoominternet.net address_country = United States num_cart_items = 3 mc_handling1 = 0.00 mc_handling2 = 0.00 mc_handling3 = 0.00 address_city = San Jose payer_email = bbb_1233964418_per@zoominternet.net mc_shipping1 = 5.44 mc_shipping2 = 0.00 mc_shipping3 = 0.00 txn_id = 9M838033K29070309 payment_type = instant last_name = User address_state = CA item_name1 = Medium Sausage Pizza receiver_email = sss_1233964440_biz@zoominternet.net item_name2 = Medium Ham and Pinnapple Pizza payment_fee = 1.93 item_name3 = Medium Ham and Cheddar Pizza quantity1 = 1 quantity2 = 2 receiver_id = THLEVDLL2GVXE quantity3 = 5 txn_type = cart mc_gross_1 = 11.79 mc_currency = USD mc_gross_2 = 12.70 mc_gross_3 = 31.75 residence_country = US transaction_subject = 3 payment_gross = 56.24'; preg_match_all('/item_name(\d+) = (.*)/', $test, $item); $item = array_combine($item[1], $item[2]); preg_match_all('/quantity(\d+) = (.*)/', $test, $quantity); $quantity = array_combine($quantity[1], $quantity[2]); foreach ($item as $key => $i){ echo $i, ' - ', $quantity[$key], "<br />\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766604 Share on other sites More sharing options...
zang8027 Posted February 19, 2009 Author Share Posted February 19, 2009 i cant figure out how to get all the results into a variable.. i tried putting the foreach ($_POST as $key => $val) { return $key . " => " . $val . "<br />"; } into a function and putting $test = "".postResults()."": but that only returns the first value (mc_gross). Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766653 Share on other sites More sharing options...
zang8027 Posted February 20, 2009 Author Share Posted February 20, 2009 it works,i just need to figure out how to put the results (that entire list) into a variable Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766679 Share on other sites More sharing options...
samshel Posted February 20, 2009 Share Posted February 20, 2009 you already have the information in the array and u just need to find the items ? or you want to put the information in an array and find the items ? Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766681 Share on other sites More sharing options...
zang8027 Posted February 20, 2009 Author Share Posted February 20, 2009 well, its probably easier to put the items into the variable like in sasa's $test variable. I am echoing out each of these "$GET" params using a foreach($arraykey as $key=>$val). Thats how I got that entire list to echo onto my page. I need to place that in a variable just like in sasa's example. Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766685 Share on other sites More sharing options...
samshel Posted February 20, 2009 Share Posted February 20, 2009 function returnString() { $str = ""; foreach ($_POST as $key => $val) { $str .= $key . " = " . $val . "\n"; } return $str; } echo returnString(); Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766686 Share on other sites More sharing options...
zang8027 Posted February 20, 2009 Author Share Posted February 20, 2009 thanks, it works.. tho i had that return function before and it didn't work haha maybe cause i didnt first declare it as an empty var Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766689 Share on other sites More sharing options...
Q695 Posted February 20, 2009 Share Posted February 20, 2009 The true data dump of all data can be found at: http://www.phpfreaks.com/forums/index.php/topic,238332.html Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-766817 Share on other sites More sharing options...
samshel Posted February 20, 2009 Share Posted February 20, 2009 thanks, it works.. tho i had that return function before and it didn't work haha maybe cause i didnt first declare it as an empty var even though u were running foreach loop, you were returning inside the loop, so the return was executed first time your loop ran, u just had to put the return outside the foreach. Quote Link to comment https://forums.phpfreaks.com/topic/145986-need-a-foreach/#findComment-767470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.