Jump to content


Photo

Regex question


  • Please log in to reply
8 replies to this topic

#1 kkroo

kkroo
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 May 2006 - 03:18 PM

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

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 16 May 2006 - 04:02 PM

[!--quoteo(post=374300:date=May 16 2006, 11:18 AM:name=kkroo)--][div class=\'quotetop\']QUOTE(kkroo @ May 16 2006, 11:18 AM) View Post[/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:
<?php
preg_match('|\<input.+?\>|i', $text, $matches);
echo "<pre>\n";
print_r($matches);
echo "</pre>\n";
?>

if you're looking for more specific occurrences WITHIN those tags, it would take a bit more
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 kkroo

kkroo
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 May 2006 - 05:03 PM

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.

#4 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 16 May 2006 - 05:12 PM

[!--quoteo(post=374340:date=May 16 2006, 01:03 PM:name=kkroo)--][div class=\'quotetop\']QUOTE(kkroo @ May 16 2006, 01:03 PM) View Post[/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"
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#5 kkroo

kkroo
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 May 2006 - 05:19 PM

That wouldnt work for every site because one site might have more inputs than another so...

#6 ryanlwh

ryanlwh
  • Staff Alumni
  • Advanced Member
  • 511 posts

Posted 16 May 2006 - 06:09 PM

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.
Please use EDIT * 100...
Please use
or [php] * 1000...

PLEASE READ THE POSTED SOLUTIONS CAREFULLY * 1000000...

#7 kkroo

kkroo
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 May 2006 - 06:22 PM

ya that is true but i would like it to work on most sites

#8 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 16 May 2006 - 07:05 PM

[!--quoteo(post=374375:date=May 16 2006, 02:22 PM:name=kkroo)--][div class=\'quotetop\']QUOTE(kkroo @ May 16 2006, 02:22 PM) View Post[/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:
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
  }
}

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.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#9 kkroo

kkroo
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 16 May 2006 - 07:17 PM

that is exatly what i did a minute ago, thanks a lot




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users