繁体   English   中英

PHP file_get_contents和domxpath UTF-8编码问题

[英]PHP file_get_contents and domxpath UTF-8 encoding issue

我正在读取一个包含以下内容的外部文件:

<td>ÖZGÜR&nbsp;</td>

我这样看:

$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;
}

它不回声ÖZGÜR ,但回声 ZGÜR

我应该在这里调用哪种编码功能?

谢谢你的帮助 !

你应该使用

mb_internal_encoding(“ UTF-8”);

更改编码的功能,而不是

$ html = str_replace(“ charset = iso8859-9”,“ charset = utf-8”,$ html);

如果数据存储在数据库中,则需要在获取数据时更改连接编码。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM