3

When using $_SERVER[REQUEST_URI] am getting a string like following one

"/stardigitalprint/index.php?route=product/product&path=59_61&product_id=50"

How to take the parts after question mark, ie

"product/product&path=59_61&product_id=50"

Your help is much appreciated Thank you.

Dibish
  • 9,133
  • 22
  • 64
  • 106

4 Answers4

12

The server variable $_SERVER['QUERY_STRING'] should contain what you are looking for.

Richard Adnams
  • 3,128
  • 2
  • 22
  • 30
  • Is that a question to OP :P – Tushar Gupta Feb 10 '15 at 10:09
  • Dire ct copy paste of here?? http://stackoverflow.com/questions/8469767/get-url-query-string – Tushar Gupta Feb 10 '15 at 10:10
  • No I just wrote that answer, after several years of PHP development you would think I remember how to access the query string :-) - albeit I used the same word 'contains' .. I see your logic. – Richard Adnams Feb 10 '15 at 10:11
  • U getting offended right.... I was just wondering how the answers have the same wordings – Tushar Gupta Feb 10 '15 at 10:13
  • No you haven't offended me, don't worry. – Richard Adnams Feb 10 '15 at 10:16
  • @RichardAdnams Thank you so much for your code. Its working. Now am getting "route=product/product&path=59_61&product_id=50". I want only following part "product/product&path=59_61&product_id=50". sorry for my mistake – Dibish Feb 10 '15 at 10:19
  • Excellent, you should have a look here http://php.net/manual/en/function.parse-str.php there is a built in function that will parse the query string into an array allowing you to access the parts you need by key. – Richard Adnams Feb 10 '15 at 10:21
2
$parts = explode("?", $_SERVER[REQUEST_URI]);
echo $parts[1];

You'll need to check whether the uri has some get params or not

Phate01
  • 2,499
  • 2
  • 30
  • 55
0
$str = "/stardigitalprint/index.php?route=product/product&path=59_61&product_id=50";
echo substr($str , strpos($str , "?") + 1); 

Please have a look :

So I guess this will work for you.

echo substr($_SERVER[REQUEST_URI] , strpos($_SERVER[REQUEST_URI] , "?") + 1);

ScoRpion
  • 11,364
  • 24
  • 66
  • 89
0

The parts after the question mark are called "Query String". There are plenty of answeres here if someone is still getting to this page

Shai
  • 318
  • 6
  • 15