tags:

views:

61

answers:

3

I'm pulling some text from a database, which contains some carriage returns. When I put them straight into html, they get interpreted as � . I've tried a bunch of different ways to remove them, but haven't seemed to have any luck.

Any thoughts?

+2  A: 
select Replace(myColumn,CHAR(13),'')

Have you tried this? What else have you tried?

Fosco
If it's also line-feeds, you can check for both with Replace(Replace(myColumn,CHAR(13),''),CHAR(10),'')
Fosco
Tried this.. still getting the � character.
MetalAdam
Then it isn't carriage returns or line-feeds. It must be another character, or encoding. I would use the SQL tools to identify that character and get the ordinal value.
Fosco
+1  A: 

Well, if you want to keep the carriage returns, use nl2br otherwise use $val = str_replace(array('\r\n', '\r', '\n'), ' ', $val);

Trefex
nl2br doesn't catch the � character for some reason.
MetalAdam
Mhhh all I see is ? in a black box and this could be any character not recognized by my charset. So I'm not sure which character it actually is you're displaying...
Trefex
That's the character that is being displayed in my web page. If I look at it through the MySQL Browser, the character resembles a backwards P with an extra | attached to the bottom...
MetalAdam
Did you simply try trim() ?
Trefex
+2  A: 

It sounds like character encoding conflicts. Other previous suggestions are fine for a quick fix, but if you control the data I think you'd be better off figuring out and sticking to a single character set. If you read from a UTF-8 database and include that text on a website, don't tell the browser that you're serving ISO-8859-1 or Windows-1252.

thetaiko
I don't control the database, just have access to the information. Any suggestions how I would go about determining the character set of the database?
MetalAdam
`SHOW VARIABLES LIKE 'character_set_database';`
thetaiko
value=latin1I've changed my page to:<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />However, still getting the character...
MetalAdam
You might try and force the browser to render the page using difference charsets - its possible that the data saved in the database is encoded incorrectly.
thetaiko
Got it. turns out I needed to use utf8_encode on the string. You got me on the right track, though. Thanks!!!
MetalAdam