regex to match text inbetween first and last tag not working

Below is the example

$lol = '<p>one</p>two</p>three<p>last</p><div>';



For the string above I want output like one</p>two</p>three<p>last but its not working for above code.But when I remove the <div> at the end I get the correct output.Can some one explain why.

Source: regex

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.