Jump to content

Regex question


kkroo

Recommended Posts

[!--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]
<?php
preg_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

[!--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

[!--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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.