input:
$string = "a b c d e";
i have a string in php and I need to replace the string with the non-break space code
output:
"a \xc2\xa0b c \xc2\xa0d \xc2\xa0\xc2\xa0e"
- single space and the first space is not allowed to replace with \xc2\xa0
- when two space appear " ", the output is " \xc2\xa0", first space is kept and the second space is replace.
- when three spaces appear " ", the output is " \xc2\xa0\xc2\xa0", first space is kept and the second and third space is replaced.
- the input string is randomly
Any idea with the Regular expression or other function of php Thank you very much.