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

PHP Server Side Scripting Forum

    
preg match to get value
ahmed24




msg:4234432
 11:58 am on Nov 24, 2010 (gmt 0)

hello,

i've got a variable called $content that has the following html field

<input type="hidden" name="POID" value="125233">

the field varies from time to time and i'd like to know how I can retrieve the value of POID using preg_match

any ideas?

 

Readie




msg:4234942
 3:57 pm on Nov 25, 2010 (gmt 0)

preg_match('/<input[^>]*?value="([^"]*)"[^>]*?>/mis', $content, $out);
echo $out[1];

Matthew1980




msg:4235005
 7:34 pm on Nov 25, 2010 (gmt 0)

Hi all,

Cheers Readie, I have been trying to figure that one out for most of today! Is there any way of using the \d switch in that to 'condense' the pattern in anyway?

I know I am being cheeky in asking that, but in essence, ahmed24 you have a working solution there; I tried this myself, as I wanted something similar to this a while back...

Kudos to Readie!

Cheers,
MRb

Readie




msg:4235047
 9:26 pm on Nov 25, 2010 (gmt 0)

Suppose you could change ([^"]*) to (\d*) - didn't want to assume that the value was only ever going to be an int field though :)

Made a mistake in the whole thing anyways. Will just grab the first input atm :)

preg_match('/<input[^>]*?(?:name="POID"[^>]*?value="([^"]*)"|value="([^"]*)"[^>]*?name="POID")[^>]*?>/mis', $content, $out);
echo $out[1]


Should do the trick

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