Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Whats the quickest way to extract data from string?

11:57 pm on Jan 9, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 15, 2004
votes: 0


As I have screwed my mod rewrite (!) I need to extract some information from the url.


"$id = $HTTP_GET_VARS['id'];" doesn't work for some reason if the url doesn't have a slash at the end...


(If the slash is there, then it works fine?)

So I need to quickly extract the value of id (in the above examples 'xxxx').

Whats the best way of doing this? I was thinking about moving it into an array and reading backwards(?).

Thanks in advance

12:14 am on Jan 10, 2006 (gmt 0)


WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 24, 2001
votes: 0

maybe take a look at parse_url [php.net] and see if that helps
10:02 am on Jan 10, 2006 (gmt 0)

Junior Member

10+ Year Member

joined:Mar 15, 2004
votes: 0

Thanks for that, but I couldnt get it to work. Is there anyway that I can scan a string for a value (in this instance 'id_' and return the starting position?

Edit : Nevermind, found it! (strpos)

2:40 pm on Jan 10, 2006 (gmt 0)

New User

10+ Year Member

joined:Jan 10, 2006
votes: 0

you could also use the explode string function on "id_"
3:21 pm on Jan 10, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 8, 2004
votes: 0

$name = ltrim( basename( $_SERVER['PHP_SELF'] ), "id_" );