I have 1000 HTML documents, which inside I have
$contenido="<p>TFJFA<div>whatsapp</div></p><p>second parragraph</p><p>third parragraph </p><p>night</p>";
I need to remove the first </p> tag; the result must be:
$contenido="<p>second parragraph</p><p>third parragraph </p><p>night</p>";
I’ve tried to use this regular expression, but it doesn’t work.
$pattern = '/\<p\>.*?\</p\>(.*)/';
$contenido=preg_replace($pattern, '$1'. $contenido);
Your pattern contains an un-escaped
/within it, and you’re also using/as your regex delimiter (i.e./regex/). You can either escape the internal/(in the closing tag) or use a different delimiter:OR (I like this option better, it’s easier to understand – I chose ‘@’ as the delimiter):
Also, instead of replacing that with
$1, you could just have your pattern as@<p>.*?</p>@, replace with'', and feed in 1 as the$limitargument topreg_replace.