I would like to remove all   if is not in front one of this character !?:;% with preg_replace ( I supose ) .

<div>&nbsp;Hello&nbsp;!
&nbsp;&nbsp;&nbsp;&nbsp;
Am I 100&nbsp;% clear&nbsp;?&nbsp;</div>

It should give me

<div>Hello&nbsp;! Am I 100&nbsp;% clear&nbsp;?</div>

Thanks in advance

有帮助吗?

解决方案

Use negative lookahead:

$str = preg_replace('/&nbsp;(?![!?:;%])/', '', $str);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top