0

I am working on a small php script I have an html code like this :

<p>text1</p> <p>text2</p> <p>text3</p>

Is it possible to use php to get only the content of the first paragraph which is text1 ?

chris85
  • 23,591
  • 7
  • 30
  • 47

1 Answers1

0

Yes, is possible:

$text = '<p>text1</p> <p>text2</p> <p>text3</p>';
$text = preg_replace('/<\/p>[ ]{1,}<p>/', '</p><p>', $text);
$splitedText = explode('</p>', $text);
var_dump(substr($splitedText[0],3));

I Hope this helps!

xXx
  • 620
  • 10
  • 25