在读取站点's元标签后转换特殊字符


converting special characters after reading a site's meta tags

我从一个外部站点用这个代码拉Facebook元标签,它的工作:

$site = file_get_contents($link);
$html = new DOMDocument();
@$html->loadHTML($site);
$meta_title = null;
foreach($html->getElementsByTagName('meta') as $meta) {
    if($meta->getAttribute('property')=='og:title'){ 
        $meta_title = $meta->getAttribute('content');
    }
 }
echo 'og:title: '.$meta_title;

我的问题是,如果og:title包含带有撇号的内容,例如,它会输出一堆时髦的字符。例如:

that -€™s the Spot

代替:

那就是点

如何使其正确输出?

检查第三部分网站排序,是utf-8还是拉丁文

那么你应该转换到你的网站整理。你在用什么?Utf8还是拉丁语?

如果使用utf8和第三部分拉丁语,则应该使用

utf8_encode($actualVar)

如果使用拉丁文和第三部分utf8,则应该使用

utf8_decode($actualVar)

我想有两种不同的排序规则。把你的php头也转换成UTF8:

header('Content-Type: text/html; charset=utf-8');

如果您尝试使用拉丁文(iso-8859-1)使用

header('Content-Type: text/html; charset=iso-8859-1');

无论如何靠墙都可以

解决方案是在PHP文件的顶部包含UTF-8编码元标记。

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />