Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 12th, 2007, 8: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
Old Dec 12th, 2007, 1:26 PM   #2
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,076
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Re: Removing double spaces with str_replace

Are you positive that it's what comes from the database? Output it and then check the HTML (not what appears in the browser). This is because it could be using " " for a space, which appears to be a space in your browser, but is not the case in the data.

There could also be a newline, or something else. So make sure you're comparing it to the outputted HTML.
Sane is offline   Reply With Quote
Old Dec 12th, 2007, 6:19 PM   #3
davil
Newbie
 
Join Date: Nov 2007
Posts: 27
Rep Power: 0 davil is on a distinguished road
Re: Removing double spaces with str_replace

Thanks. I'll try that when I get back to work on Monday.
davil is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between double and Double in C# jonyzz C# 14 Jan 18th, 2007 7:38 AM
double functions (getting weird numbers) j0nathan C++ 4 Apr 5th, 2006 3:53 AM
How do i use a ^ for a double variable? dvu C# 4 Feb 3rd, 2006 10:27 AM
Problem converting double to int Jared C++ 2 Feb 18th, 2005 2:53 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC