Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/148.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何更改由简单HTMLDOM检索的网页的编码?_Php_Encoding_Simple Html Dom - Fatal编程技术网

Php 如何更改由简单HTMLDOM检索的网页的编码?

Php 如何更改由简单HTMLDOM检索的网页的编码?,php,encoding,simple-html-dom,Php,Encoding,Simple Html Dom,我正在尝试阅读网页的内容 $html = file_get_html('http://www.example.com/somepage.aspx'); 由于页面的编码是Windows-1254,并且我处理的页面编码为UTF-8,因此我无法替换某些具有特定语言字符的单词 例如: 如果我试着 $str2 = str_replace('TÜRKÇE', 'TURKCE', $str); 它不能取代 我尝试了htmlentities函数,但删除了一些包含特殊字符的单词。仅适用于utf-8。如果在其他

我正在尝试阅读网页的内容

$html = file_get_html('http://www.example.com/somepage.aspx');
由于页面的编码是Windows-1254,并且我处理的页面编码为UTF-8,因此我无法替换某些具有特定语言字符的单词

例如:

如果我试着

$str2 = str_replace('TÜRKÇE', 'TURKCE', $str);
它不能取代


我尝试了htmlentities函数,但删除了一些包含特殊字符的单词。

仅适用于utf-8。如果在其他编码中有一些数据,请将其转换。如果您不知道编码,请尝试定义它。如果不能,请使用用户。然后只对所有字符串操作使用mb_*函数,这很重要!有些函数在本机php中不存在,但在php.net/上搜索它的手工实现。。在注释中。

在获得字符串后,我使用了iconv'Windows-1254','utf-8',$str函数,这要感谢。这解决了我的问题

你试过这个吗:str_'TÜ;RKÇ;E“,”土耳其“,$str@是的,我试过了。这听起来像是一份工作