0

Possible Duplicate:
RegEx match open tags except XHTML self-contained tags

What is the fastest Regular Expression, to catch the ending of the first <div></div> tag-wrapper?

$strTemplateResult = 

    '<div id="myIdMayBeDifferent" class="myClassMayBeDifferent">

       <!-- match here. stop ! -->

       <p>Don't be confused because of some neat lorem ipsum dolor.</p>

    </div>';
Community
  • 1
  • 1
mate64
  • 9,876
  • 17
  • 64
  • 96

1 Answers1

0

Consider giving up on the idea of parsing your HTML with regex, and use something like simple html dom.

$html = file_get_html($html);
$div = $html->find('div', 0);

Otherwise yes, you may awake to find HTML tags lea͠ki̧n͘g fr̶ǫm ̡yo​͟ur eye͢s̸ ̛l̕ik͏e liq​uid pain.

Community
  • 1
  • 1
Michael Robinson
  • 29,278
  • 12
  • 104
  • 130
  • I need this snippet for a framework hook. I can not access the parent class, so it's galaxies faster to prepare the template in the background to serve the cached file by varnish. – mate64 Feb 21 '12 at 19:49
  • If anyone uses zalgo text in an input, they deserve to break their own page and get mad. Regex is usually the most simple solution without having to use an external library just for one entire line of code. – Nahydrin Feb 21 '12 at 19:54
  • Sure he can do what he wants! Personally I'd rather use a DOM and be more sure it'll work every time than be forced to go back and fix some odd bug in 3 months caused by an edge case for some regex I wrote then promptly forgot about. – Michael Robinson Feb 21 '12 at 19:57
  • Whatever, I've found a simple solution. – mate64 Feb 21 '12 at 20:17