I've seen this asked several times, but not with a good resolution. I have the following string:
$string = "<p>Résumé</p>";
I want to print or echo the string, but the output will return <p>R�sum�</p>
. So I try htmlspecialchars()
or htmlentities()
which outputs <p>Résumé<p>
and the browser renders <p>Résumé<p>
. I want it, obviously, to render this:
Résumé
And I'm using UTF-8:
header("Content-type: text/html; charset=UTF-8");
What am I missing here? Why does echo and print output a �
for any special character? To clarify, the string is actually an entire html file stored in a database. The real world application is not just that one small line.
In PHP there is a pretty good function utf8_encode() to solve this issue.
Check the official PHP page.
If you've got it working where it displays
Résumé
with<p></p>
tags around it, then just don't convert the paragraph, only your string. Then the paragraph will be rendered as HTML and your string will be displayed within.This works for me. Try this one before the start of HTML. I hope it will also work for you.