kkroo Posted May 16, 2006 Share Posted May 16, 2006 Hello, I am a major regex noob, and i would like to know how to find an input for forms in a page ex:<input type="x" name="x" value="x">Thanks in advance Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 16, 2006 Share Posted May 16, 2006 [!--quoteo(post=374300:date=May 16 2006, 11:18 AM:name=kkroo)--][div class=\'quotetop\']QUOTE(kkroo @ May 16 2006, 11:18 AM) [snapback]374300[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hello, I am a major regex noob, and i would like to know how to find an input for forms in a page ex:<input type="x" name="x" value="x">Thanks in advance[/quote]i'm not sure i totally understand what you're after. if you want to grab the entire tag for each input field, just do something like this:[code]<?phppreg_match('|\<input.+?\>|i', $text, $matches);echo "<pre>\n";print_r($matches);echo "</pre>\n";?>[/code]if you're looking for more specific occurrences WITHIN those tags, it would take a bit more Quote Link to comment Share on other sites More sharing options...
kkroo Posted May 16, 2006 Author Share Posted May 16, 2006 thanks a lot, well, how would i find a submit button? I am trying to make this as flexible as possible because i am making my own proxy and i know that all websites code HTML a bit differently. Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 16, 2006 Share Posted May 16, 2006 [!--quoteo(post=374340:date=May 16 2006, 01:03 PM:name=kkroo)--][div class=\'quotetop\']QUOTE(kkroo @ May 16 2006, 01:03 PM) [snapback]374340[/snapback][/div][div class=\'quotemain\'][!--quotec--]thanks a lot, well, how would i find a submit button? I am trying to make this as flexible as possible because i am making my own proxy and i know that all websites code HTML a bit differently.[/quote]well, a submit button has to have a type="submit", so i would just search for the input tags and then check each one to see that type="submit" Quote Link to comment Share on other sites More sharing options...
kkroo Posted May 16, 2006 Author Share Posted May 16, 2006 That wouldnt work for every site because one site might have more inputs than another so... Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted May 16, 2006 Share Posted May 16, 2006 you can't make it work for EVERY site, because some of them might be using a javascript button, some of them use malformed html, etc. Quote Link to comment Share on other sites More sharing options...
kkroo Posted May 16, 2006 Author Share Posted May 16, 2006 ya that is true but i would like it to work on most sites Quote Link to comment Share on other sites More sharing options...
obsidian Posted May 16, 2006 Share Posted May 16, 2006 [!--quoteo(post=374375:date=May 16 2006, 02:22 PM:name=kkroo)--][div class=\'quotetop\']QUOTE(kkroo @ May 16 2006, 02:22 PM) [snapback]374375[/snapback][/div][div class=\'quotemain\'][!--quotec--]ya that is true but i would like it to work on most sites[/quote]probably not the best solution, but this will work:[code]preg_match_all('|\<input(.+?)\>|i', $content, $matches, PREG_PATTERN_ORDER);foreach ($matches[1] as $match) { if (preg_match('|input\="submit"|i', $match)) { // it's a submit button, so do what you need }}[/code]keep in mind that this only checks for "input="submit"", if you want to check for "input=submit" and input='submit'" as well, you'll have to modify the second check slightly. Quote Link to comment Share on other sites More sharing options...
kkroo Posted May 16, 2006 Author Share Posted May 16, 2006 that is exatly what i did a minute ago, thanks a lot Quote Link to comment 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.