PHP library that extracts/parses meta details of an x/html body, including open graph details, meta tags and images.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Inspired by Facebook's link sharing flow, this abstractly accessed class attempts to parse a document (x/html), and retrieve it's meta-information. I emphasize attempts, as x/html documents are exceptionally tough to parse, and data is often lost due to the content structuring delivered.

This class, as seen by the example below, works very well when coupled with the PHP-Curler class.
The following is an example of how data is returned, using as an example:

    [base] =>
    [favicon] =>
    [meta] => Array
            [description] => Breaking news, sport, ...
            [keywords] => Array
                    [0] => BBC
                    [1] =>
                    [6] => BBCi


    [images] => Array
            [0] =>
            [1] =>
            [2] =>
            [3] =>
            [25] =>

    [openGraph] => Array
            [title] => BBC - Homepage
            [type] => website
            [image] =>
            [url] =>

    [title] => BBC - Homepage
    [url] =>

Parsing Example

The following code uses the PHP-Curler class to curl the BBC site, store it's content, and pass it along to a MetaParser instance. The URL is passed along as well to ensure any paths (favicons, images) are rewritten relative to the path of the document that was parsed.


    // booting
    require_once APP . '/vendors/PHP-Curler/Curler.class.php';
    require_once APP . '/vendors/PHP-MetaParser/MetaParser.class.php';
    // curling
    $curler = new Curler();
    $url = '';
    $body = $curler->get($url);
    $parser = new MetaParser($body, $url);