如果< >
为空,是否可以删除它?
文本可以是;
< > 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.
答案 0 :(得分:1)
您可以使用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.
如果您还想清除空<>
的行中的任何多个或悬挂的空格(在行的开头或结尾),则可以使用以下代替:
$text = preg_replace(array('/<\s*\>/', '/\s+/', '/^\s|\s$/'), array('', ' ', ''), $text);