0

I have a string as follows

http://solo.dev/module-1/behavioural-safety/?id=7#15

and I want to get the id value for the above string, normally $_GET['id'], however not an option as this is being executed elsewhere.

What's the best way to get this value from the above string?

Jack hardcastle
  • 2,471
  • 3
  • 17
  • 36
  • I do not know if it's the best practice. However you can first split on ? then on = to have the two vars, first the var name, second the value – Goikiu Jun 15 '15 at 09:39
  • Aye this was my go to, however my concern is, what if there's more than one query in the URL? @Goikiu – Jack hardcastle Jun 15 '15 at 09:40
  • after the first split (on ?) you can search, if present semicolumn (;) you'll have more then one var, otherwise you got only one problably :) – Goikiu Jun 15 '15 at 09:41
  • 1
    You can try this `$request_uri ="http://solo.dev/module-1/behavioural-safety/?id=7#15"; $url = explode('?', $request_uri); $url = end($url); $url = explode("#", $url); print_r($url[0]);` – Haris Jun 15 '15 at 09:52

0 Answers0