mauris / htmlmeta
HTML meta 读取/写入器
1.0.0
2013-07-10 22:48 UTC
Requires
- php: >=5.3.0
- symfony/dom-crawler: 2.3.*
This package is not auto-updated.
Last update: 2024-09-21 11:06:17 UTC
README
#HtmlMeta
HtmlMeta 提供了 PHP 中 HTML meta 标签读取和写入的抽象。您可以直接使用此库生成或解析 HTML 内容中的 meta 标签,或使用 HtmlMeta 的 OpenGraph 或 Twitter Cards 实现,以丰富您的搜索引擎优化和用户体验。
##安装
您可以通过 Composer 安装 HtmlMeta,命令为 mauris/htmlmeta
。请参阅 https://packagist.org.cn/packages/mauris/htmlmeta。
##写入 <meta>
<?php use HtmlMeta\Writer; $writer = new Writer(); $writer->add(new Meta(array('charset' => 'utf8'))); $writer->add(new Meta(array('name' => 'description', 'content' => 'some description'))); echo $writer->render();
输出到
<meta charset="utf8" /> <meta name="description" content="some description" />
##读取 <meta>
<?php use HtmlMeta\Reader; $reader = new Reader(); $data = $reader->parse(file_get_contents('http://www.nytimes.com/2013/07/09/world/middleeast/egypt.html')); print_r($data);
输出到
Array ( [0] => HtmlMeta\Meta Object ( [attributes:protected] => Array ( [http-equiv] => Content-Type [content] => text/html; charset=utf-8 ) ) [1] => HtmlMeta\Meta Object ( [attributes:protected] => Array ( [itemprop] => inLanguage [content] => en-US ) ) [2] => HtmlMeta\Meta Object ( [attributes:protected] => Array ( [itemprop] => description [name] => description [content] => In a sharp escalation of tensions Monday, Egyptian soldiers opened fire on hundreds of supporters of Mohamed Morsi, the ousted president, witnesses said. The military said armed assailants fired first. ) ) ... )