Jump to content

Archived

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

kkroo

Regex question

Recommended Posts

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

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
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"

Share this post


Link to post
Share on other sites
That wouldnt work for every site because one site might have more inputs than another so...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
ya that is true but i would like it to work on most sites

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.