Sorry if this question is already somewhere but I need a more pratical approach:
The page is set like this:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
later in php i use the following line
$v .= "<a href='" . $videoEntry->getVideoWatchPageUrl() . "' rel='vidbox' title='" . $videoEntry->getVideoTitle() . "'><img src='";
…
$v .= "<td width='52%' height='16'><strong>Visualizações:</strong> " . $videoEntry->getVideoViewCount() . "</td>";
ok. now
When i do
echo $v;
Itajubá em Foco Canal20 Oficina de Cuidados Paliativos (correct)
Visualiza��es: 204 //(incorrect)
if i try
echo utf8_encode($v);
Itajubá em Foco Canal20 Oficina de Cuidados Paliativos //(incorrect)
Visualizações: 204 //(correct)
I tried to use the
header(‘Content-type: text/html; charset=utf-8’);
but with no success.
If the data from the database is coming out OK as UTF-8, but the static content you have in the .php file itself isn’t, that means you’re not saving your PHP file itself as UTF-8 in your text editor. Probably you have saved as Windows code page 1252 (Western European); make sure to change that on the save dialogue box (to UTF-8; if there is a separate option for ‘UTF-8 without BOM’ choose that, as UTF-8-with-BOM is utterly bogus).
If your text editor later gets the symbols wrong when it loads the file back, you’ll need to tell it to load file by default in UTF-8 mode. If it doesn’t have that option, it’s rubbish and should be replaced. If you really can’t replace it you will have to forgo Unicode characters in your source file and encoding them, either as HTML:
or, specifically in a PHP string literal:
incidentally you need to be using
htmlspecialcharswhen you’re putting text into HTML, as otherwise you’ve got XSS bugs.