0
$data = '<p>&nbsp;</p>
<p>&nbsp;</p> 
<p>hello</p> 
<ul>
 <li>&nbsp;</li>
 <li>&nbsp;</li>
</ul> 
<p>hello</p>
<p>&nbsp;</p>
<p>&nbsp;</p>';

$regex = preg_replace('/^((<[a-z]+>)(&nbsp;)(<\/[a-z]+>))/','',$data);
$regex = preg_replace('/((<[a-z]+>)(&nbsp;)(<\/[a-z]+>))$/','',$regex);
echo $regex;

i am able to remove only single line of code at top and bottom, while the next line i can't able to remove.even i have tried this code also

$regex = preg_replace('/^((<[a-z]+>)(&nbsp;)(<\/[a-z]+>))*/','',$data);
$regex = preg_replace('/((<[a-z]+>)(&nbsp;)(<\/[a-z]+>))*$/','',$regex);
echo $regex;

my exact output want to be like this

<p>hello</p>
<ul>
<li>&nbsp;</li>
<li>&nbsp;</li>
</ul>
<p>hello</p>

1 Answers1

0

use str_replace , hope its work

$regex = str_replace("<p>&nbsp;</p>",'',$data);
Tausif
  • 420
  • 2
  • 15