homepage Welcome to WebmasterWorld Guest from 54.211.47.170
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Whats the quickest way to extract data from string?
PumpkinHead




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

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

 

jatar_k




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

maybe take a look at parse_url [php.net] and see if that helps

PumpkinHead




msg:1257869
 10:02 am on Jan 10, 2006 (gmt 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)

stu_uk




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

you could also use the explode string function on "id_"

twist




msg:1257871
 3:21 pm on Jan 10, 2006 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved