ΒΆ β
PHP SelectorQuick 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
ΒΆ β
ExamplesGiven 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);
ΒΆ β
SelectorDOMPersistant object for element selection.
$dom = new SelectorDOM($html); $links = $dom->select('a'); $list_links = $dom->select('ul li a');
ΒΆ β
Contribution-
Like it? use it? feel free to extend and add more CSS3 support, and run test.selector.php
ΒΆ β
More Information-
View the source :P
ΒΆ β
License(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.