10

I abstracted the header from a larger set of php files for clarity. When I load it into Wampserver, the <p>é</p> 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.php:

<?php
    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">
    <head>
        <title>Blabla</title>
    </head>
    <body>
        <p>é</p>
    </body>
</html>
JDelage
  • 13,036
  • 23
  • 78
  • 112

3 Answers3

15

try this<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> in the head section

and also check your file encoding

Headshota
  • 21,021
  • 11
  • 61
  • 82
  • Problem was the file encoding (it was ANSI), so this takes care of it. Thanks! – JDelage Mar 29 '11 at 12:00
  • Adding the following line in the html works for me: . NOTE: Make sure your text file encoding is Default (determined from content: Cp1252) – Supercoder Nov 21 '20 at 21:15
11

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.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • @JDelage you're welcome. But do also fix the contradiction, it may give you problems in the long term – Pekka Mar 29 '11 at 12:01
  • Yes, but I had tried it and it had not solved the problem, whereas encoding the actual PHP file in Notepad++ does solve things. – JDelage Mar 29 '11 at 13:24
1

this worked for me : I add to the MVC COntroller : produces={"application/json;charset=utf-8"}