PHP only catch the last <p> </p> (paragraph)

Asked

Viewed 83 times

0

I have a text like this coming from MYSQL (can be text with several paragraphs):

<p>Nam convallis, odio eget ullamcorper eleifend, tortor sapien.</p>
<p>Aenean quis nibh turpis. Vestibulum posuere ex.</p>
<p>In interdum auctor maximus.</p>
<p>MOSTRAR SÓ ESSE</p>

I wanted to echo just in the last <p>, how can it be done?

1 answer

2


Good I got here!

$recebe_texto = "<p>Nam convallis, odio eget ullamcorper eleifend, tortor sapien.</p><p>Aenean quis nibh turpis. Vestibulum posuere ex.</p><p>In interdum auctor maximus.</p><p>MOSTRAR SÓ ESSE</p>";
preg_match_all('#<p>.*</p>#', $recebe_texto, $resultado);
$ultimo_paragrafo = array_pop($resultado[0]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.