euskadi31 / opengraph
A PHP 5.3+ framework for OpenGraph Protocol
Installs: 430 831
Dependents: 4
Suggesters: 0
Security: 0
Stars: 92
Watchers: 12
Forks: 16
Open Issues: 2
Requires
- php: >=5.3.0
Requires (Dev)
- phpunit/phpunit: 9.5.26
This package is auto-updated.
Last update: 2024-11-29 04:35:48 UTC
README
Test with Atoum
cd Opengraph/
curl -s https://getcomposer.org/installer | php
php composer.phar install --dev
./vendor/bin/phpunit -c phpunit.xml.dist
Writer
<?php namespace Application; require_once __DIR__ . '/../src/Opengraph/Meta.php'; require_once __DIR__ . '/../src/Opengraph/Opengraph.php'; require_once __DIR__ . '/../src/Opengraph/Writer.php'; use Opengraph; $writer = new Opengraph\Writer(); $writer->append(Opengraph\Writer::OG_TITLE, 'The Rock'); $writer->append(Opengraph\Writer::OG_TYPE, Opengraph\Writer::TYPE_VIDEO_MOVIE); $writer->append(Opengraph\Writer::OG_URL, 'http://www.imdb.com/title/tt0117500/'); $writer->append(Opengraph\Writer::OG_IMAGE, 'http://ia.media-imdb.com/images/rock.jpg'); echo $writer->render() . PHP_EOL; ?>
Output
<meta property="og:title" content="The Rock" /> <meta property="og:type" content="video.movie" /> <meta property="og:url" content="http://www.imdb.com/title/tt0117500/" /> <meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />
Reader
<?php namespace Application; require_once __DIR__ . '/../src/Opengraph/Meta.php'; require_once __DIR__ . '/../src/Opengraph/Opengraph.php'; require_once __DIR__ . '/../src/Opengraph/Reader.php'; use Opengraph; $reader = new Opengraph\Reader(); $reader->parse(file_get_contents('http://www.imdb.com/title/tt0117500/')); print_r($reader->getArrayCopy()); ?>
Output
Array
(
[og:url] => http://www.imdb.com/title/tt0117500/
[og:title] => Rock (1996)
[og:type] => video.movie
[og:image] => Array
(
[0] => Array
(
[og:image:url] => http://ia.media-imdb.com/images/M/MV5BMTM3MTczOTM1OF5BMl5BanBnXkFtZTYwMjc1NDA5._V1._SX98_SY140_.jpg
)
)
[og:site_name] => IMDb
[fb:app_id] => 115109575169727
)