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>
(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.
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.
<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");
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.
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.
try this<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
in the head section
and also check your file encoding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With