I have this string:
$String = "profile.php?userId=55";
I want to get the number 55, this code just not do it:
$getID = explode("=",$String,2);
Oops, I didn't read your question too well. My answer makes no sense, sorry.
$getID;. In PHP array's are 0-based, i.e., the first part is in
$getID; and the second part is in
In cases like this it's always a good idea to do a
var_dump($getID); to see what's going on.
Also... i wouldnt do it this way unless you -know- that the URL will only ever contain one variable.
For example; if someone sent this as your string:
Then your script will tell you that the value of userId is "55&moo=cow"
For this purpose I'd suggest using some more elegant solutions:
parse_url() to get the query part.
parse_str() to get the userId. This way your code is future-proof in case you add more parameters in the future.
Thank you Lemon,
That's exactly what I'm looking for. Very appreciated.
This topic is now closed. New replies are no longer allowed.