Skip to content
项目

关于

PHP DOM 解析器,支持使用 CSS 选择器查询。

网站与应用开发

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Quick DOM query library I whipped up for an old PHP data miner I had which needed more flexibility.

Current supports most CSS3 selectors.

Tested with php 5.2.8

Given the sample html:

$html = <<<HTML
  <div id="article" class="block large">
    <h2>Article Name</h2>
    <p>Contents of article</p>
    <ul>
      <li>One</li>
      <li>Two</li>
      <li>Three</li>
      <li>Four</li>
      <li><a href="#">Five</a></li>
    </ul>
  </div>
HTML;

The following will return an array of elements:

select_elements('div#article.large', $html);
select_elements('div > h2:contains(Article)', $html);
select_elements('div p + ul', $html);
select_elements('ul > li:first-child', $html);
select_elements('ul > li ~ li', $html);
select_elements('ul > li:last-child', $html);
select_elements('li a[href=#]', $html);

Persistant object for element selection.

$dom = new SelectorDOM($html);
$links = $dom->select('a');
$list_links = $dom->select('ul li a');
  • Like it? use it? feel free to extend and add more CSS3 support, and run test.selector.php

  • View the source :P

(The MIT License)

Copyright © 2008 - 2009 TJ Holowaychuk <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

探索相关项目

加载中…