Php – Bad characters in apache on debian

apache-2.2debianPHP

I have an Apache server on a Debian machine,

I also have PHP installed on it, there are some bad characters, shown on all sites that are hosted on that machine.

For example instead of

it's 

it shows

it�s

I think this is probably an Apache issue because the same code and database works perfectly elsewhere, I'm not absolutely sure though, so what kind of things would I have to do to fix this?

Best Answer

Looks like something is wrong with the character encoding. A few things you can try:

Have you tried setting the charset of your HTML output explicitly to match the charset of your database?For example, if your database has UTF-8, try declaring it in a meta tag inside de <head> tags:

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 

For HTML 5 it is far shorter:

<meta charset="UTF-8" />

For mysql, you can figure out which character set your db is using by executing the following statements:

USE <databasename>;
SHOW VARIABLES LIKE 'character_set_database';

Other DBMS will have similar statements.

However, I don't think you need to repeat this for every page/site (but it certainly doesn't hurt if you do): It is of course easier to change Apache's default charset adjusting the AddDefaultCharset directive in httpd.conf or apache2.conf or wherever your main configuration is located:

# AddDefaultCharset Somethingelse
AddDefaultCharset UTF-8

Reload apache afterwards.

Related Topic