Welcome to WebmasterWorld Guest from 54.145.173.147

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)

10+ Year Member



Hi,

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

www.mydomain.com/widgets_blue/type_001/id_#*$!x
www.mydomain.com/widgets_red/type_003/id_xxxx
www.mydomain.com/widgets_yellow/type_002/id_xxxx

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

www.mydomain.com/widgets_yellow/type_002/id_xxxx/

(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



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

10+ Year Member



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)

5+ Year Member



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

WebmasterWorld Senior Member 10+ Year Member



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