open mb_convert_encoding file_get_contents ejemplos php utf-8 character file-get-contents

php - file_get_contents - mb_convert_encoding



file_get_contents no funciona con utf8 (1)

Cambie su Accept-Charset a UTF-8 porque ISO-8859-1 no es compatible con caracteres tailandeses. Si está ejecutando su script PHP en una máquina con Windows, también puede usar el windows-874 caracteres windows-874 , y también puede intentar agregar este encabezado:

Content-Language: th

Pero en la mayoría de los casos, UTF-8 manejará la mayoría de los personajes o conjuntos de caracteres sin ninguna otra declaración.

** ACTUALIZACIÓN **

Muy extraño, pero esto funciona para mí.

$opts = array( ''http''=>array( ''method''=>"GET", ''header''=> implode("/r/n", array( ''Content-type: text/plain; charset=TIS-620'' //''Content-type: text/plain; charset=windows-874'' // same thing )) ) ); $context = stream_context_create($opts); //$fp = fopen(''http://thaipope.org/webbible/01_002.htm'', ''rb'', false, $context); //$contents = stream_get_contents($fp); //fclose($fp); $contents = file_get_contents("http://thaipope.org/webbible/01_002.htm",false, $context); header(''Content-type: text/html; charset=TIS-620''); //header(''Content-type: text/html; charset=windows-874''); // same thing echo $contents;

Aparentemente, me equivoqué con este sobre UTF-8. Mira aquí para más detalles. Aunque todavía puede tener una salida UTF-8:

$in_charset = ''TIS-620''; // == ''windows-874'' $out_charset = ''utf-8''; $opts = array( ''http''=>array( ''method''=>"GET", ''header''=> implode("/r/n", array( ''Content-type: text/plain; charset='' . $in_charset )) ) ); $context = stream_context_create($opts); $contents = file_get_contents("http://thaipope.org/webbible/01_002.htm",false, $context); if ($in_charset != $out_charset) { $contents = iconv($in_charset, $out_charset, $contents); } header(''Content-type: text/html; charset='' . $out_charset); echo $contents; // output in UTF-8

Estoy tratando de obtener caracteres tailandeses de un sitio web. He intentado:

$rawChapter = file_get_contents("URL"); $rawChapter = mb_convert_encoding($rawChapter, ''UTF-8'', mb_detect_encoding($rawChapter, ''UTF-8, ISO-8859-1'', true));

Cuando hago esto, los personajes vuelven como:

¡ÅѺ˹éÒáá¾ÃФÑÁÀÁÕÕììÑÒ

Pero si tomo el origen de la página que estoy intentando cargar y guardo en mi propio archivo .htm en mi servidor local como un archivo utf8, entonces carga los caracteres tailandeses correctamente. Solo cuando intento cargarlo desde el sitio, se rompe.

¿Cómo puedo arreglar esto? ¿Cual podría ser el problema?

También intenté agregar este contexto:

$context = stream_context_create(array( ''http'' => array( ''method'' => ''POST'', ''header'' => implode("/r/n", array( ''Content-type: application/x-www-form-urlencoded'', ''Accept-Language: en-us,en;q=0.5'', ''Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'' )) ) ));

He intentado agregarlo solo, he intentado agregarlo con mb_convert_encoding () ... Siento que he probado todas las combinaciones de estas cosas y no he tenido éxito.