简体   繁体   中英

PHP file_get_contents and domxpath UTF-8 encoding issue

I'm reading an external file which contains this :

<td>ÖZGÜR&nbsp;</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 .

what type of encoding function should I call here ?

Thanks for any help !

you should use

mb_internal_encoding("UTF-8");

function to change the encoding instead of

$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

使用file_get_contents设置后,尝试将$ html转换为utf8

$html = iconv('ISO-8859-9', 'UTF-8', $html);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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