tags:

views:

269

answers:

3

Hello,

I have a sentence like this.

1 $nbsp;     2     3   4

As you see, in between 1 2 and 3 text, there are extra spaces. I want the output with only one space between them. so my output will be 1 2 3 4

How can i use php trim to get the output like this. If i use trim, it can only remove whitespace, but not that  

Thanks.

+2  A: 
$str = "1 $nbsp;     2     3   4";
$new_str = str_replace(" ", '', $str);
Lotus Notes
Thus delegating the work of whitespace stripping to the browser?
Duncan
A: 

if your string actually has "  ",

$str="1       2     3   4";
$s = str_replace("  ","",$str);
print $s;
ghostdog74
A: 
echo str_replace ( " ", "", "1       2     3   4" );

just remember you need to echo out the result of the str_replace and you alo dont need to worry about white spaces a the browser will only show one white space.

Steve Obbayi