删除空的 < >

Remove empty < >

如果 < > 是空的,有没有办法删除它?

正文可以; < > Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, < > when an <b>unknown printer</b> took <> a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries. < >

输出应该是; Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an <b>unknown printer</b> took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries.

您可以使用 preg_replace:

$text = "<  > Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, < > when an <b>unknown printer</b> took <> a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries. <     >";
$text = preg_replace('/<\s*\>/', '', $text);
echo $text;

输出:

 Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,  when an <b>unknown printer</b> took  a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries. 

Demo on 3v4l.org

如果您还想通过删除空 <> 来清理任何多个或悬挂的空格(在行首或行尾),您可以改用此方法:

$text = preg_replace(array('/<\s*\>/', '/\s+/', '/^\s|\s$/'), array('', ' ', ''), $text);

Demo on 3v4l.org