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?

4
  • 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 Commented Jun 15, 2015 at 9:39
  • Aye this was my go to, however my concern is, what if there's more than one query in the URL? @Goikiu Commented Jun 15, 2015 at 9: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 :) Commented Jun 15, 2015 at 9: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]); Commented Jun 15, 2015 at 9:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.