preg replace - remove   if is not in front one of this character !?:;% -


i remove   if not in front 1 of character !?:;% preg_replace ( supose ) .

<div>&nbsp;hello&nbsp;! &nbsp;&nbsp;&nbsp;&nbsp; 100&nbsp;% clear&nbsp;?&nbsp;</div> 

it should give me

<div>hello&nbsp;! 100&nbsp;% clear&nbsp;?</div> 

thanks in advance

use negative lookahead:

$str = preg_replace('/&nbsp;(?![!?:;%])/', '', $str); 

Comments

Popular posts from this blog

Why can rails not find a route created by a helper? -

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -