質問

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