| Welcome to WebmasterWorld Guest from 18.104.22.168 |
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
|Subscribe and Support WebmasterWorld|
|preg match to get value|
| 11:58 am on Nov 24, 2010 (gmt 0)|
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
| 3:57 pm on Nov 25, 2010 (gmt 0)|
preg_match('/<input[^>]*?value="([^"]*)"[^>]*?>/mis', $content, $out);
| 7:34 pm on Nov 25, 2010 (gmt 0)|
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!
| 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);
Should do the trick
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
© Webmaster World 1996-2014 all rights reserved