首页›网络›Document 文档解析
Document 文档解析
Kuoqi\Document(77 行):基于 DOMDocument + DOMXPath 的 HTML/XML 解析
方法清单
| 方法 | 签名 | 说明 |
|---|---|---|
__construct | ($domString="") | 自动编码转 UTF-8、抑制 libxml 错误 |
loadHTML | loadHTML($domString) | 加载 HTML |
evaluate | evaluate($xPath) | XPath 取首个匹配节点 html |
select | select($xPath) | 返回 NodelistDocument 列表 |
find | find($xPath) | 返回 ElementDocument 元素 |
典型用法
$doc = new \Kuoqi\Document($html);
// XPath 取值
$title = $doc->evaluate("//title");
$links = $doc->select("//a[@class='item']");
$links->each(function($el){
echo $el->text();
});
$first = $doc->find("//div[@id='main']");
echo $first->outerHtml();
KuoqiPHP v1.05 · 离线静态文档 · 界面基于 KuoqiUI ·
返回首页