Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 <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>
like image 493
JDelage Avatar asked Mar 29 '11 11:03

JDelage


People also ask

Are there any problems with accents and strange characters in PHP?

(1 minute read) Usually, when creating a website in PHP and MySQL, there’s a problem when introducing accents and strange characters, typically from foreign languages like Spanish or French: these get changed into áóñand similar strange stuff.

What is the use of header_sent() in PHP?

This PHP function allows checking whether or where the headers were sent. But note that after the header block has already been sent, no more header lines can be added with the header function. For more examples of using the header_sent () function, you can refer to this source.

How to output HTML without HTML headers in PHP?

<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> And in those files you output without HTML headers (XML, AJAX/JSON calls, APIs…) put this in the PHP: header("Content-Type: text/html;charset=utf-8");

What is the default encoding for htmlentities?

htmlentities() takes an optional third argument encoding which defines encoding used in conversion. If omitted, the default value for this argument is ISO-8859-1 in versions of PHP prior to 5.4.0, and UTF-8 from PHP 5.4.0 onwards. Drove me crazy for two hours until I found this William says: February 11th, 2013 at 21:53 Thank You.


2 Answers

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.

like image 66
Pekka Avatar answered Nov 02 '22 22:11

Pekka


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

and also check your file encoding

like image 32
Headshota Avatar answered Nov 03 '22 00:11

Headshota