| Welcome to WebmasterWorld Guest from 184.108.40.206 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|preg match to get value|
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
preg_match('/<input[^>]*?value="([^"]*)"[^>]*?>/mis', $content, $out);
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!
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);
Should do the trick
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved