Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 读取站点后转换特殊字符';s元标记_Php - Fatal编程技术网

Php 读取站点后转换特殊字符';s元标记

Php 读取站点后转换特殊字符';s元标记,php,Php,我正在使用以下代码从外部站点提取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'

我正在使用以下代码从外部站点提取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包含带撇号的内容,例如,它会输出一堆时髦的字符。例如:

那是€™什么地方

而不是:

就是这个地方


如何使其正确输出?

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

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

检查第三方网站的排序,它是utf-8或拉丁语

然后,您应该转换为您的网站排序规则。你在用什么?utf8还是拉丁语

如果您使用的是utf8和第三部分拉丁语,那么应该使用

utf8_encode($actualVar)
utf8_decode($actualVar)
如果使用拉丁语和第三部分utf8,则应使用

utf8_encode($actualVar)
utf8_decode($actualVar)
我想有两种不同的排序规则。如果是两个UTF8,请将php标头也转换为UTF8:

header('Content-Type: text/html; charset=utf-8');
如果您试图使用拉丁语(iso-8859-1),请使用


靠墙应该可以用任何方法。

不要使用@,检查是否有危险errors@Phantom我删除了@并打开了错误报告-无。这是我正在使用的URL: