0
<(form)[^>]*method=(['\"])post(['\"]).*</(form)>

Currently i've got that.. which kind of works if there is no new line involved.. but I'm not sure how to search for everything (including input fields) inside of the form tag

Any help is appreciated :]

Adam Merrifield
  • 10,307
  • 4
  • 41
  • 58
  • 1
    As always: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags Do NOT use regex for this. Use DOM+XPATH to find/extract the form tag, then use innerHTML to retrieve its guts. – Marc B May 24 '11 at 19:52
  • Also, be careful with extra capturing parenthesis. – sidyll May 24 '11 at 19:53

3 Answers3

9
$html = "<form>your form stuff here</form>"

$dom = new DOM;
$dom->loadHTML($html);
$xp = new XPath($dom);

$form = $xp->query('//form')->item(0);

$guts = $form->saveHTML();
Marc B
  • 356,200
  • 43
  • 426
  • 500
1

HI

$pattern = "/<form\b[^>]*>(.*?)<\/form>/is";
Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
Senad Meškin
  • 13,597
  • 4
  • 37
  • 55
0
preg_match_all('%<form.*?</form%i', $subject, $result, PREG_PATTERN_ORDER);
for ($i = 0; $i < count($result[0]); $i++) {
    # Matched text = $result[0][$i];
}
daalbert
  • 1,465
  • 9
  • 7
  • 1
    It may work, but we should not push answers that we know are way suboptimal, as people may use them... and I guess none of us would like to maintain a system based on that... – mdrg May 24 '11 at 19:56