sokil / php-social-opengraph
lib to work with OpenGraph
Installs: 39
Dependents: 1
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/sokil/php-social-opengraph
Requires (Dev)
- phpunit/phpunit: >=4.8.35 <6.0
This package is auto-updated.
Last update: 2025-09-28 04:40:35 UTC
README
Lib to render open graph.
Installation
composer require sokil/php-social-opengraph
Basic Usage
// Open Graph $openGraph = new \Sokil\OpenGraph; $openGraph ->setTitle('The Matrix Revolutions') ->setDescription('The human city of Zion ...') ->setType(\Sokil\OpenGraph::TYPE_PRODUCTS_MOVIE) ->setImage('https://server.com/Matrix_Revolutions_poster.jpg') ->setUrl('http://www.imdb.com/title/tt0242653/') ->setVideoUrl('https://server.com/3453245.torrent') ->setVideoType('application/x-bittorrent');
Then you can get opengraph as array. This may be useful to render meta tags in frameworks. Example for Yii:
$cs = Yii::app()->getClientScript(); foreach($openGraph->toArray() as $property => $content) { $cs->registerMetaTag($content, null, null, array( 'property' => $property, )); }
You can render meta tags directly:
echo $openGraph->render(); // or just: echo $openGraph;