PHP only get the last p / p (paragraph)

0

I have text like this coming from MYSQL (it can be multi-paragraph text):

<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 only the last <p> , how can it be done?

    
asked by anonymous 24.05.2016 / 19:47

1 answer

2

I got it right 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]);
    
24.05.2016 / 20:10