在我的网站中,用户可以保存书签,
用户提交网址后,我会查找<title>
,<meta description>
和<meta keywords>
值,以帮助用户从网站恢复数据,
问题是,我怎么能 - 如果我能用PHP读取那些变量,例如http://domain.com/?
- 编辑 -
尝试这样但总是返回NULL
$url = '';
if(isset($_GET['url'])){
$url = $_GET['url'];
}
echo '<form><input type="text" name="url" id="url" placeholder="Introduce un dominio" value="'.$_GET['url'].'" /><input type="submit" hidden /></form><hr />';
echo '<h1 class="titulo">Examinando URL: <span>'.$url.'</span></h1><hr />';
if($url <> ''){
libxml_use_internal_errors(true); // Yeah if you are so worried about using @ with warnings
$doc = new DomDocument();
$doc->loadHTML(file_get_contents($url));
$xpath = new DOMXPath($doc);
$query = '//*/meta[starts-with(@property, \'og:\')]';
$metas = $xpath->query($query);
foreach ($metas as $meta) {
$property = $meta->getAttribute('property');
$content = $meta->getAttribute('content');
$rmetas[$property] = $content;
echo $rmetas;
}
var_dump($rmetas);
}else{
echo '<p class="error">Introduce una URL</p>';
}