简体   繁体   中英

DOMDocument on WordPress site causing UTF-8 issues

I'm building a mobile site at https://mobile.pugetsoundbasketball.com .

On the home page ( https://mobile.pugetsoundbasketball.com ) I'm using DOMDocument to pull content from a specific div (#upcoming_league_dates) from a page located on the main website ( https://pugetsoundbasketball.com ).

The main website is built in WordPress and I don't want to use WordPress on the mobile site because I only need to pull a couple WordPress pages.

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

This works but my problem is it's showing what I believe is UTF-8 characters like "Men€s" instead of "Men's".

I tried to change the text in WordPress to see if I can fix it that way but no luck.

Tell DOM what charset to use from the get-go:

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

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