- $html = Encoding::toUTF8(get_external_file($url,15));
- // If get_external_file if not able to retrieve HTTPS content try the same URL with HTTP protocol
- if (!preg_match('!^https?://!i', $url) && (!isset($html) || strlen($html) <= 0)) {
- $url = 'http://' . $url;
- $html = Encoding::toUTF8(get_external_file($url,15));
- }
+ $html = Encoding::toUTF8(get_external_file($url,15));
+ // If get_external_file if not able to retrieve HTTPS content try the same URL with HTTP protocol
+ if (!preg_match('!^https?://!i', $url) && (!isset($html) || strlen($html) <= 0)) {
+ $url = 'http://' . $url;
+ $html = Encoding::toUTF8(get_external_file($url,15));
+ }
+
+ if (function_exists('tidy_parse_string')) {
+ $tidy = tidy_parse_string($html, array(), 'UTF8');
+ $tidy->cleanRepair();
+ $html = $tidy->value;
+ }