Estoy cargando un HTML desde un servidor externo. El marcado HTML tiene codificación UTF-8 y contiene caracteres tales como L, S, C, T, Z etc. Cuando cargo el HTML con file_get_contents() como este:file_get_contents() Descompone caracteres UTF-8
$html = file_get_contents('http://example.com/foreign.html');
se mete el UTF-8 caracteres y cargas Å, ¾, ¤ y tonterías similares en lugar de los caracteres UTF-8 apropiados.
¿Cómo puedo solucionar esto?
ACTUALIZACIÓN:
He intentado tanto salvar el HTML en un archivo y la salida con codificación UTF-8. Ambos no funcionan, por lo que significa que file_get_contents() ya está devolviendo HTML roto.
Update2:
<!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="sk" lang="sk">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Language" content="sk" />
<title>Test</title>
</head>
<body>
<?php
$html = file_get_contents('http://example.com');
echo htmlentities($html);
?>
</body>
</html>
¿Los emite con UTF-8? –
¿Dónde está viendo el HTML cargado? –
No lo estoy produciendo. Lo guardo en un archivo y luego lo leo. Pero es irrelevante porque traté de producirlo con UTF-8 y todavía está en mal estado. Re –