Welcome to WebmasterWorld Guest from 54.166.191.159

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

preg match to get value

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

5+ Year Member



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?
3:57 pm on Nov 25, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



preg_match('/<input[^>]*?value="([^"]*)"[^>]*?>/mis', $content, $out);
echo $out[1];
7:34 pm on Nov 25, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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
9:26 pm on Nov 25, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



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
 

Featured Threads

Hot Threads This Week

Hot Threads This Month