ketting00 — 2012-12-06T08:02:51-05:00 — #1
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);
guido2004 — 2012-12-06T08:16:36-05:00 — #2
Oops, I didn't read your question too well. My answer makes no sense, sorry.
scallioxtx — 2012-12-06T08:30:53-05:00 — #3
$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.
starlion — 2012-12-06T08:48:24-05:00 — #4
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"
lemon_juice — 2012-12-06T18:31:55-05:00 — #5
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.
ketting00 — 2012-12-06T21:46:12-05:00 — #6
Thank you Lemon,
That's exactly what I'm looking for. Very appreciated.