sokil/ php-social-opengraph
用于操作 OpenGraph 的库
1.0.1
2018-06-13 07:49 UTC
Requires (Dev)
- phpunit/phpunit: >=4.8.35 <6.0
This package is auto-updated.
Last update: 2024-08-28 02:00:44 UTC
README
用于渲染 OpenGraph 的库。
安装
composer require sokil/php-social-opengraph
基本用法
// 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');
然后你可以得到 opengraph 数组。这可能有助于在框架中渲染 meta 标签。例如,在 Yii 中
$cs = Yii::app()->getClientScript(); foreach($openGraph->toArray() as $property => $content) { $cs->registerMetaTag($content, null, null, array( 'property' => $property, )); }
你可以直接渲染 meta 标签
echo $openGraph->render(); // or just: echo $openGraph;