删除空白<>

问题描述 投票:0回答:1

如果为空< >,是否可以删除?

文本可以是;< > 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.

php php-7
1个回答
1
投票

您可以使用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);

© www.soinside.com 2019 - 2024. All rights reserved.