JDelage JDelage - 1 year ago 48
HTML Question

Header says UTF-8 but accents not showing up properly - why? (php)

I abstracted the header from a larger set of php files for clarity. When I load it into Wampserver, the

appears as � on the site, despite the header calling for utf-8 charset. What is wrong in this document?

(Note that I tried to modify the encoding by replacing iso-8859-1 with utf-8, that didn't help.)


header('Content-Type:text/html; charset=UTF-8');
echo '<?xml version="1.0" encoding="iso-8859-1"?>'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">

Answer Source

You are sending two contradicting character sets, iso-8859-1 and utf-8.

If you

  • fix that and send only one character set, and

  • encode the actual file in the character set you specify (there should be a character set option in your IDE's or editor's "Save as..." dialog)

it should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download