문제

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