繁体   English   中英

WordPress网站上的DOMDocument导致UTF-8问题

[英]DOMDocument on WordPress site causing UTF-8 issues

我正在https://mobile.pugetsoundbasketball.com上建立一个移动网站。

在主页( https://mobile.pugetsoundbasketball.com )上,我正在使用DOMDocument从主网站( https://pugetsoundbasketball.com )上的特定div(#upcoming_league_dates)中提取内容。

主要网站是使用WordPress构建的,我不想在移动网站上使用WordPress,因为我只需要拉几个WordPress页面即可。

$url = "https://pugetsoundbasketball.com/index.php";
$doc = new DomDocument('1.0', 'UTF-8');
$doc->validateOnParse = true;
$doc->loadHtml(file_get_contents($url));
$div = $doc->getElementById('upcoming_league_dates');
echo $doc->saveHTML($div);

这行得通,但我的问题是它显示的是UTF-8字符,例如“ Men€s”而不是“ Men's”。

我试图在WordPress中更改文本,以查看是否可以通过这种方式修复它,但是没有运气。

从一开始就告诉DOM使用什么字符集:

$doc = new DOMDocument('1.0', 'UTF-8');  // note the UTF-8 option.
$doc->loadHTML(file_get_contents($url));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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