ressio/pharse
Composer 安装命令:
composer require ressio/pharse
包简介
Fastest PHP HTML Parser
README 文档
README
Fastest PHP HTML Parser
The Pharse is fork of Ganon library and gives access to HTML/XML documents in a very simple object oriented way. It eases modifying the DOM and makes finding elements easy with CSS3-like queries.
Pharse is:
- A universal tokenizer
- A HTML/XML/RSS DOM Parser
- Ability to manipulate elements and their attributes
- Supports HTML5
- Supports invalid HTML
- Supports UTF8
- Can perform advanced CSS3-like queries on elements (like jQuery -- namespaces supported)
- A HTML beautifier (like HTML Tidy)
- Minify CSS and Javascript
- Sort attributes, change character case, correct indentation, etc.
- Extensible
- Parsing documents using callbacks based on current character/token
- Operations separated in smaller functions for easy overriding
- Fast
- Easy
Quick start
include('path/pharse.php'); // Parse the google code website into a DOM $html = Pharse::file_get_dom('http://code.google.com/');
After including Pharse and loading the DOM, it is time to get started.
Access
Accessing elements is made easy through the CSS3-like selectors and the object model.
// Find all the paragraph tags with a class attribute and print the // value of the class attribute foreach($html('p[class]') as $element) { echo $element->class, "<br>\n"; } // Find the first div with ID "gc-header" and print the plain text of // the parent element (plain text means no HTML tags, just the text) echo $html('div#gc-header', 0)->parent->getPlainText(); // Find out how many tags there are which are "ns:tag" or "div", but not // "a" and do not have a class attribute echo count($html('(ns|tag, div + !a)[!class]');
Modification
Elements can be easily modified after you've found them.
// Find all paragraph tags which are nested inside a div tag, change // their ID attribute and print the new HTML code foreach($html('div p') as $index => $element) { $element->id = "id$index"; } echo $html; // Center all the links inside a document which start with "http://" // and print out the new HTML foreach($html('a[href ^= "http://"]') as $element) { $element->wrap('center'); } echo $html; // Find all odd indexed "td" elements and change the HTML to make them links foreach($html('table td:odd') as $element) { $element->setInnerText('<a href="#">'.$element->getPlainText().'</a>'); } echo $html;
Beautify
Pharse can also help you beautify your code and format it properly.
// Beautify the old HTML code and print out the new, formatted code Pharse::dom_format($html, array('attributes_case' => CASE_LOWER)); echo $html;
License
Pharse is licensed under the Artistic License/GPL
ressio/pharse 适用场景与选型建议
ressio/pharse 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 83.56k 次下载、GitHub Stars 达 85, 最近一次更新时间为 2015 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「parser」 「HTML5」 「html」 「dom」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ressio/pharse 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ressio/pharse 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ressio/pharse 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HTML5 support for SilverStripe
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
HTML5 Boilerplate is a professional front-end template for building fast, robust, and adaptable web apps or sites.
An MT940 bank statement parser for PHP
The yii2-videojs-widget is a Yii 2 wrapper for the [video.js](http://www.videojs.com/). A JavaScript and CSS library that makes it easier to work with and build on HTML5 video. This is also known as an HTML5 Video Player.
Laravel integration for the jsonapi.org parser
统计信息
- 总下载量: 83.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 86
- 点击次数: 23
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: GPL
- 更新时间: 2015-03-23