[英]PHP file_get_contents and domxpath UTF-8 encoding issue
I'm reading an external file which contains this : 我正在读取一个包含以下内容的外部文件:
<td>ÖZGÜR </td>
And I read it like this : 我这样看:
$html = file_get_contents("");
$html = str_replace("charset=iso8859-9" , "charset=utf-8" , $html);
$rows = $x->query('//tr[contains(@class,"tablerow")]');
foreach($rows as $node)
{
echo $node->childNodes->item(12)->nodeValue;
}
it does not echo ÖZGÜR
, but it echoes ZGÜR
. 它不回声
ÖZGÜR
,但回声 ZGÜR
。
what type of encoding function should I call here ? 我应该在这里调用哪种编码功能?
Thanks for any help ! 谢谢你的帮助 !
you should use 你应该使用
mb_internal_encoding("UTF-8"); mb_internal_encoding(“ UTF-8”);
function to change the encoding instead of 更改编码的功能,而不是
$html = str_replace("charset=iso8859-9" , "charset=utf-8" , $html); $ html = str_replace(“ charset = iso8859-9”,“ charset = utf-8”,$ html);
if data is stored in database than you need to change the connection encoding at the time of data fetching. 如果数据存储在数据库中,则需要在获取数据时更改连接编码。
mysql_set_charset('utf8',$constring) than you will be able to retrieve in the UTF-8 format mysql_set_charset('utf8',$ constring)比您将能够以UTF-8格式检索
使用file_get_contents设置后,尝试将$ html转换为utf8
$html = iconv('ISO-8859-9', 'UTF-8', $html);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.