我正在尝试从链接al:android:url
中获取特定属性https://www.facebook.com/tobiasz.mencfel
。
当前代码:字符串$link_id
不显示任何内容。
到目前为止,我已经完成了:
function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36');
$html = curl_exec($ch);
curl_close($ch);
return $data;
}
$html = file_get_contents_curl("https://www.facebook.com/tobiasz.mencfel");
$doc = new DOMDocument();
@$doc->loadHTML($html);
$metas = $doc->getElementsByTagName('meta');
for ($i = 0; $i < $metas->length; $i++) {
$meta = $metas->item($i);
if ($meta->getAttribute('property') == 'al:android:url') {
$link_id = $meta->getAttribute('content');
}
}
// output should be: fb://profile/100025596917906
echo $link_id;
元数据的样子:
<meta property="al:android:url" content="fb://profile/100025596917906" />
答案 0 :(得分:1)
//modify
return $data;
//to
return $html;
//result : fb://profile/100025596917906