如果为空< >
,是否可以删除?
文本可以是;< > 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
:
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);