file_get_html que devuelve símbolos extraños

$html = file_get_html("");

echo $html; 

$html is returned as a bunch of strnage symbols that include vۺ�(

I though that using:

header('Content-Type: text/html; charset=utf-8');

would help, but it didn't. Any suggestions?

preguntado el 17 de mayo de 13 a las 07:05

Utilice las html_entity_decode. -

Doesn't work. I'm not sure why. -

What character encoding is it on your page? The page you linked to has ISO-8859-1. -

The character encoding isn't specified on my page. It's not html. It's strictly php. -

@Lance, yes ok it's php, but output must have some encoding. If you haven't defined it explicitly it would still have some character-encoding (that is set default). Can you see the character-encoding of the source php-code? (through your ide) -

3 Respuestas

Prueba esto:

$url = '';
$html = str_get_html(utf8_encode(file_get_contents($url)));

echo $html;

contestado el 17 de mayo de 13 a las 08:05

@Lance Edited. How about this? - mpyw

Prueba esta

$encoded = htmlentities(utf8_encode(file_get_html('yoururl')));
echo $encoded;

It will convert the special characteres to HTML entity.

Please see the doc aquí.

contestado el 17 de mayo de 13 a las 08:05

Doesn't echo anything. It's just a plain white page. - Lance

var_dump returns string(0) - Lance

Please try my edit, I added utf8_encode funcionar dentro htmlentities. - ola

Corrupted page content ? You really should "force" all page to be UTF-8 so. - ola

How can I force the page to be UTF-8? - Lance

file_get_contents is screwy sometimes. Change the code in simple_html_dom.php que se utilizará gzopen en lugar de. Bajo file_get_html()

//$contents = file_get_contents($url, $use_include_path, $context, $offset);

//get the contents of the page
$fp = gzopen($url,'r');

$contents = '';

while($html = gzread($fp , 256000))
    $contents .= $html;


Respondido el 12 de junio de 14 a las 22:06

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.