I have user defined string (html formated string to be saved and used in web) and need to find a way to replace each white space which is right after a single letter by
without regex
$str = "this is a string" ; $s = explode(" ",$str); foreach ($s as $i => $j){ if (strlen($j)==1){ $s[$i]="$j "; } } print_r ( implode(" ",$s) );