1

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>';
        }

Test: http://toniweb.us/opengraph

Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378
  • 3
    A combination of file_get_contents (or CURL, to get the site contents) and DOMDocument (which parses the HTML). – jValdron Jan 30 '12 at 16:47
  • you might have to fabricate a `user agent` too, as some sites have protection from scraping of this nature... – Lix Jan 30 '12 at 16:50
  • you should add the XML chunk you have a problem with probably. – hakre Jan 31 '12 at 13:42

0 Answers0