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 Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/ 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 Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/#findComment-36271 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. Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/#findComment-36296 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" Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/#findComment-36301 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... Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/#findComment-36304 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. Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/#findComment-36325 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 Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/#findComment-36331 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. Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/#findComment-36347 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 Link to comment https://forums.phpfreaks.com/topic/9784-regex-question/#findComment-36352 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.