why does a – Paul DelRe Sep 09 '11 at 21:49

  • @Paul DelRe indeed that looks like the same problem, which he solved by using a different DOM parser. I guess my choice is between doing that or just using a regex to remove the scripts. – jela Sep 09 '11 at 21:59
  • 2 Answers2

    0

    A div doesn't belong inside a script tag. Javascript belongs inside a script tag.

    Take the div out of the script tag and it should be fine.

    Jared
    • 12,406
    • 1
    • 35
    • 39
    • 1
      My problem is that I have no control over the html to be parsed, and this html contains divs inside scripts. I'm wondering if the only way to get it to work is to use a hack like removing the scripts with a regex before parsing. – jela Sep 09 '11 at 21:12
    -1

    The trick is simple, change loadHTML to loadXML with one condition,
    the HTML string has to be always well-formed

    $dom->loadXML($html2);
    
    ajreal
    • 46,720
    • 11
    • 89
    • 119