waynew Posted June 16, 2009 Share Posted June 16, 2009 I need to scrape out the value of a hidden field. The field name will be like so: <input type="hidden" value="9337700952" name="MemberId"/> The only thing that is different each time is the value. Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/162368-solved-preg-match-hidden-field/ Share on other sites More sharing options...
waynew Posted June 16, 2009 Author Share Posted June 16, 2009 Tried the following but I get a blank screen. $pattern = '/<input type="hidden" value="([^"]*)" name="Checkit"\\/>/'; preg_match($pattern,$this->result,$match); print_r($match[0]); Quote Link to comment https://forums.phpfreaks.com/topic/162368-solved-preg-match-hidden-field/#findComment-857056 Share on other sites More sharing options...
thebadbad Posted June 16, 2009 Share Posted June 16, 2009 Why are you double escaping the forward slash? And are you sure that exactly <input type="hidden" value="..." name="Checkit"/> appears in the haystack? Your sample data says MemberId, so is Checkit right? Also be sure the cases match, or add the pattern modifier i after the last slash in the pattern to make the search case-insensitive. Quote Link to comment https://forums.phpfreaks.com/topic/162368-solved-preg-match-hidden-field/#findComment-857075 Share on other sites More sharing options...
waynew Posted June 16, 2009 Author Share Posted June 16, 2009 Hi. Tbh, I'm guessing here. I'm just trying to use code from other examples. Here's what I have: $pattern = '/<[^>]*name="Checkit"[^>]*value="([^"]+)/'; preg_match($pattern,$this->result,$matches); array_shift($matches); print_r($matches); It just printed "Array()". Here's what I found in the source ($this->result) <input type=hidden name=Checkit value=35806834> Quote Link to comment https://forums.phpfreaks.com/topic/162368-solved-preg-match-hidden-field/#findComment-857094 Share on other sites More sharing options...
waynew Posted June 16, 2009 Author Share Posted June 16, 2009 Ok. I'm getting somewhere: $pattern = '/<[^>]*name=Checkit[^>]*value=([^"]+)/'; preg_match($pattern,$this->result(),$matches); array_shift($matches); print_r($matches); It matched ok, but it also took in the code after it. So I got value=8934782348> <img src Etc Quote Link to comment https://forums.phpfreaks.com/topic/162368-solved-preg-match-hidden-field/#findComment-857096 Share on other sites More sharing options...
waynew Posted June 16, 2009 Author Share Posted June 16, 2009 Its ok! I got it! $pattern = '/<[^>]*name=Checkit[^>]*value=([0-9]+)/'; preg_match($pattern,$this->result(),$matches); array_shift($matches); print_r($matches); Woop! Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/162368-solved-preg-match-hidden-field/#findComment-857097 Share on other sites More sharing options...
thebadbad Posted June 16, 2009 Share Posted June 16, 2009 Great, was about to suggest that change But beware that your pattern also would match something weird like <div weirdname=Checkitvalue=12345 If the syntax in your source doesn't change, I would probably go with something simple like ~<input type=hidden name=Checkit value=([0-9]+)>~ Quote Link to comment https://forums.phpfreaks.com/topic/162368-solved-preg-match-hidden-field/#findComment-857106 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.