Scroll to top

28/07/2023


avatar
pimoore says: Reply to pimoore

@colinwalker Wow, they're not even trying. 0/5 stars–poor effort. 😂

avatar
Colin Walker replied:

🤣

Leave a reply



You can also:

Click here to reply using email Reply by email Send a webmention Send a Webmention



No comments yet
Leave a reply



You can also:

Click here to reply using email Reply by email Send a webmention Send a Webmention



2023/07/28#p3

0 comments: click to leave a comment

I never knew you could (should?) set the character encoding when performing a loadHTML() into a DOMDocument().

When pulling the title tag from remote pages (e.g. when doing a 'like') it would often not return characters correctly.

By specifying 'UTF-8' for both the curl request and DOMDocument it's fixed the problem:

$url = 'https://example.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
$response = curl_exec($ch);
curl_close($ch);

$dom = new DOMDocument();
$dom->loadHTML('<?xml encoding="UTF-8">' . $response);
No comments yet
Leave a reply



You can also:

Click here to reply using email Reply by email Send a webmention Send a Webmention



Close