lukaswhite/php-meta-tags-parser
Composer 安装命令:
composer create-project lukaswhite/php-meta-tags-parser
包简介
A PHP package for parsing meta tags in HTML documents
README 文档
README
Extracts metadata (title, description, Open Graph etc) from the content of a web page.
Note that this library simply deals with raw HTML, rather than try to tie you down to one particular method for retrieving the content of an external URL. (I usually use Guzzle, but to make it a dependency might cause difficulties in terms of versioning.)
Installation
composer require lukaswhite/php-meta-tags-parser
Usage
use Lukaswhite\MetaTagsParser\Parser; $html = '<html><head>...</head></html>'; $parser = new Parser(); $result = $parser->parse($html);
Using the result
The parse() method returns an object that encapsulates any page data it's extracted from the provided HTML.
$result->getTitle(); $result->getDescription(); $result->getKeywords(); $result->getUrl(); $result->getFacebookAppId(); $result->openGraph()->getSiteName(); $result->openGraph()->getType(); $result->openGraph()->getTitle(); $result->openGraph()->getDescription(); $result->openGraph()->getLocale(); $result->openGraph()->getImages(); // returns an array of URLs $result->openGraph()->getLatitude(); $result->openGraph()->getLongitude(); $result->openGraph()->getAltitude(); $result->toArray(); // all of the extracted metadata
It will also extract RSS and/or Atom feeds; getFeeds() returns an array of instances of the Feed class:
$feed->getType(); // Feed::RSS or Feed::ATOM $feed->isRSS(); $feed->isAtom(); $feed->getUri(); $feed->getTitle();
The getFeeds() method accepts an optional $type argument, to choose one or the other:
$result->getFeeds(Feed::RSS); // or $result->getFeeds(Feed::ATOM);
Cleansing the data
The package ships with a very simple string cleanser; essentially it just decodes any HTML entities. You're free to provide your own cleanser; just implement the CleansesStrings interface, and provide an instance to the parser's constructor. It simply needs to provide a run() method, that accepts a string and returns the cleansed version.
Sanitizing the data
The package ships with a very simple string sanitzer; under the hood it simply uses the strip_tags() function. If you wish to provide your own sanitizer, just implement the SanitizesStrings interface, and provide an instance to the parser's constructor. It simply needs to provide a run() method, that accepts a string and returns the sanitized version.
lukaswhite/php-meta-tags-parser 适用场景与选型建议
lukaswhite/php-meta-tags-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 549 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 12 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 lukaswhite/php-meta-tags-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lukaswhite/php-meta-tags-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 549
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-12-04