Skip to content

Commit

Permalink
Convert webpages to UTF-8 if necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
eheikes committed Aug 11, 2017
1 parent 90dc1c6 commit 98dfb03
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions toreadapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ function postEntry() {
$result = curl_exec($ch);
if ($result !== false)
{
// Look for a charset definition in the page.
// Convert to UTF-8 if necessary.
if (preg_match("#<meta[^<]*charset=([a-z0-9_-]+)#is", $result, $matches)) {
if (strtolower($matches[1]) !== 'utf-8') {
$result = mb_convert_encoding($result, 'UTF-8', $matches[1]);
}
}

// Save the <title>.
if (preg_match("#<title[^>]*>(.*)</title>#iU", $result, $matches)
and $matches[1] != "")
Expand Down

0 comments on commit 98dfb03

Please sign in to comment.