Вопрос

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