How do I remove <p> tag and its content from HTML using php

You must use this regular expression to catch <p> tag and all of its content:

'/<p\b[^>]*>(.*?)<\/p>/i'

Working example to catch and remove <p> tag and all of its content:

$title = "<div>Text to keep<p class='classExample'>Text to remove</p></div>";
$result = preg_replace('/<p\b[^>]*>(.*?)<\/p>/i', '', $title);
echo $result;

Please see live demo on Codepad

If you want to use regular expressions to parse HTML - then you will not be able to do this.

Read more about your matter here: How do you parse and process HTML/XML in PHP?


just to remove p tags you can do this

$text=str_ireplace('<p>','',$text);
$text=str_ireplace('</p>','',$text);    

Try:

If you want to remove <p> tag only

$html = "
<p> Addiction, stress and subjective wellbeing</p> 
<p> The need and significance of traditional shop lot pavements town</p> 
<p> The role of wage and benefit in engaging employee commitment</p>
";

echo strip_tags($html);

If you want to remove <p> tags and its content

$html = preg_replace('#\<p>[{\w},\s\d"]+\</p>#', "", $html);

Tags:

Html

Php