php - How can I replace single  's with a space but, not if there are multiple  s? -


i assume regular expression might trick haven't been able come 1 works. have long strings in php need clean up. in cases,   appears in stead of single space character , in other caes     (etc) appears. i'd replace of single   occurence space leave others in place intending can maintained.

any thoughts? presume regular expression used here i've been struggling making 1 for while!

you must use negative lookbehind , negative lookahead ensure don't have other   around.

$str = preg_replace('~(?<!&nbsp;)&nbsp;(?!&nbsp;)~i', ' ', $str); 

more informations lookarounds here.


Comments