0

Hello Sorry in advance if you find this question dumb. But i am integrating 2checkout payment system in my shoping cart. and 2checkout response in this way

www.mydomain.com/checkout.php/?middle_initial=&li_0_name=Jackets&li_0_productid=4&li_1_name=shirts&li_1_productid=2

Now i want to get all products ids and name.

Sama
  • 351
  • 3
  • 14

2 Answers2

1

I haven't used 2checkout before but a suggestion is to use regex through preg_match_all to fetch the Id of the products from the url since it is a fixed pattern. I have tried this and It grabbed 4 and 1 as product ids:

$url = "www.mydomain.com/checkout.php/?middle_initial=&li_0_name=Jackets&li_0_productid=4&li_1_name=shirts&li_1_productid=2";
$matches = null;
preg_match_all('/li_\d+_productid=(?<productIds>\d+)/', $url, $matches);
print_r($matches['productIds']);

Now this would output:

Array ( [0] => 4 [1] => 2 )

Hope this helps.

Osama Sayed
  • 1,993
  • 15
  • 15
  • Thanks @Osama for your answer. your ans did the trick for me. actutally i need each of product id,name,quantity and other info in loop. here what i did is `$count = count($matches['productIds']);` `for ($x = 0; $x < $count; $x++) {` `echo $_GET['li_'.$x.'_productid'];` `echo $_GET['li_'.$x.'_name'];` `}` still hoping for a better solution. i know there will be a better solution for this. – Sama Jun 21 '16 at 23:58
0

Here is the Answer

$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$matches = null;
preg_match_all('/li_\d+_productid=(?<productIds>\d+)/', $url, $matches);
print_r($matches['productIds']);
$count = count($matches['productIds']); 
for ($x = 0; $x < $count; $x++) {
echo $_GET['li_'.$x.'_productid'];
echo $_GET['li_'.$x.'_name'];
}

First Find the count of total numbers of product_ids using preg match from url then run loop.

Sama
  • 351
  • 3
  • 14