Php HTML DOM解析器UTF-8

Php HTML DOM解析器UTF-8,php,html,utf-8,domparser,Php,Html,Utf 8,Domparser,我有一个网站,但没有用UTF-8编码。我在另一个php中包含php文件。当我将编码改为UTF-8时,所有字符都被破坏了。所以我不能使用标题(…utf8 bla bla标签) include_once 'includes/simple_html_dom.php'; $ozet = file_get_contents($url); $html = str_get_html($ozet); $trozet = $html->find('div[class="TEST"]',0)->pla

我有一个网站,但没有用UTF-8编码。我在另一个php中包含php文件。当我将编码改为UTF-8时,所有字符都被破坏了。所以我不能使用标题(…utf8 bla bla标签)

include_once 'includes/simple_html_dom.php';

$ozet = file_get_contents($url);
$html = str_get_html($ozet);
$trozet = $html->find('div[class="TEST"]',0)->plaintext;
$icerik = "";
$yazi = "<span>$trozet</span>";
$uzunluk = strlen($yazi);
$sinir = 155;
if ($uzunluk > $sinir) {
$icerik = substr($yazi,0,$sinir) . "...";
}

$content.= '<i><span>'.$icerik.'</span></i>';

return $content;
应该是:

Pittsburgh kentinde sakin ve güneşli bir sabah, mesai saatinden hemen önce insanlar işlerine doğru koşturmakta, günlük telaşlarını...

我如何才能做到这一点?

要生成utf-8字符串,可以使用如下函数:


如果无法使用UTF-8,则必须将其转换为其他编码:

$yazi = mb_convert_encoding("<span>$trozet</span>", "Windows-1250", "UTF-8");
$yazi=mb_convert_编码(“$trozet”、“Windows-1250”、“UTF-8”);
请注意,并非每个网站都使用UTF-8,而且Windows-1250只支持一小部分Unicode字符

function substrutf8($str,$from,$len){
return preg_replace('#^(?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'. $from .'}'.'((?:[\x00-\x7F]|[\xC0-\xFF][\x80-\xBF]+){0,'. $len .'}).*#s','$1', $str);}
$yazi = mb_convert_encoding("<span>$trozet</span>", "Windows-1250", "UTF-8");