views:

28

answers:

4

I keep getting these weird text characters when I display user submitted text. like in the following example below. Is there a way I can fox this using PHP, CSS or something so that the characters are displayed properly?

Here is the problem text.

Problems of �real fonts� on the web. The one line summary: 
different browsers and different platforms do �hinting�

Here is my meta tag.

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
A: 

Set your page to UTF-8 encoding.

Zane Edward Dockery
+2  A: 

It's an encoding problem. Make sure you send the correct encoding to the browser. If it's UTF-8, you'll do it like this:

header("Content-type: text/html; charset=utf-8");

Also, make sure that you store the content using the same encoding throughout the entire system. Set your database tables to utf8. If you're using MySQL, run the SET NAMES utf8 query when connecting to make sure you're running in UTF-8.

These weird characters occur when you suddenly switch encoding.

Also, some functions in PHP take a $charset parameter (e.g. htmlentities()). Make sure you pass the correct charset to that one as well.

To make sure that PHP handles your charset correctly in all cases, you can set the default_charset to utf-8 (either in php.ini or using ini_set()).

Daniel Egeberg
but I already use the meta tag `<meta http-equiv="content-type" content="text/html; charset=UTF-8" />`
text
@text: That's not necessarily enough. If your web server sends a proper header, then that will take precedence over your `<meta>` tag. PHP is configured to send it with `iso-8859-1` by default.
Daniel Egeberg
A: 

Please check with the char-set in header section.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
use this below one:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

or try this one:

htmlentities($str, ENT_QUOTES);
VAC-Prabhu
A: 

Could be problem with file encoding please check that your files is correctly encoded, saved as "UTF-8 without boom", also if you are saving to database use SET NAMES UTF-8

AurimasL