In my website there is a functionality for the user to save bookmarks,
once the user submits the URL i look for the <title>
, <meta description>
and <meta keywords>
values to help the user to recover the data from the website,
question is, how can i -if i can- with php read those vars from, for example http://domain.com/ ?
-EDIT-
trying like this but allways returns 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>';
}