Replace double spaces with single spaces

I am taking posts from a WordPress blog, and displaying the latest ones on a client’s home page. However, this client has a tendency to type double spaces between sentences instead of single spaces.

On those with double spaces, IE8 shows a box and google Chrome a question mark between the sentences. I am looking for php code where there are double spaces, I want to replace it with a single space.

I have tried the regular string replace function, but this didn’t work. I still get the boxes and question marks.

$content // this is the content string
$content = str_replace(". ", ". ", “$content”);
Print $content;

Are you sure there isn’t some odd carriage-return or other hidden character?
Spaces should show up as box or question marks…

ErnieAlex,

That is what I said, that the double spaces ARE showing up as boxes on IE8 and question marks on Google Chrome. Did you mean, by any chance, that spaces should NOT be showing up at these?

If so, is there any way I can extract what character(s) that may be causing this, using some PHP code?

Well, some special characters will display as a box, not usually a question mark. Sometimes a special font will cause these issues. Are you using a different font?

You could take the variable and parse thru it with a for loop. Check each character, looking for a period and then echo the ascii values of the next four or five characters to see if an odd one shows up. You can use the “ord” function to get the decimal value. Here is a link to an ascii table so you can see what it should be.
http://www.asciitable.com/

Sponsor our Newsletter | Privacy Policy | Terms of Service