View Single Post
Old Dec 12th, 2007, 7:05 AM   #1
davil
Newbie
 
Join Date: Nov 2007
Posts: 27
Rep Power: 0 davil is on a distinguished road
Removing double spaces with str_replace

I want to replace double spaces with single spaces.

I have been able to do this before :
php Syntax (Toggle Plain Text)
  1. $new_string=str_replace(" "," ",$old_string)

this worked or I thought it did anyway with other strings but I'm guessing there's something in the problem string that I'm not seeing

anyway to get to the point this is what I have:
php Syntax (Toggle Plain Text)
  1. // $cpu_type comes in from MySQL database as: "Genuine Intel T2300" - note
  2. // the double space after Intel
  3.  
  4. echo $cpu_type;
  5.  
  6. $cpu_type = str_replace("\t"," ",$cpu_type);
  7. $cpu_type = str_replace(" "," ",$cpu_type);
  8.  
  9. echo $cpu_type;

the code above echoes the same before and after the str_replace command. What am I missing? it's definitely two spaces but as you can see I've even tried replacing a tab in case that's what it was... Are there any other characters it could be???
davil is offline   Reply With Quote