I have a problem that I couldn't figure out so far and I'd appreciate any help.
I have the following simple code:
<?php
header("Content-Type: text/html; charset=utf-8");
$body .= "begrüßen zu dürfen";
echo htmlentities($body);
echo htmlentities($body, ENT_COMPAT,'UTF-8');
?>
The first echo works while the second returns an empty string. Why does this happen?
The variable $body is a combination of a fixed string like "begrüßen zu dürfen
" and some text that comes from a mysql database with UTF-8. If I want to display the text from the DB correctly, let's call it $data, I need to use htmlentities($data, ENT_COMPAT,'UTF-8');
, so I was thinking that I can use htmlentities($body, ENT_COMPAT,'UTF-8')
to display the whole combined text (partly from DB and partly from a fixed string). However, this does not work.
Any idea how to solve this?