Is there a PHP library that facilitates manipulating html elements in a similar fashion to jquery?
PHP string manipulation functions are very counterintuitive and clunky, at least for me, and ev开发者_StackOverflow社区erytime I need to manipulate some html code before outputting it it takes too much time.
I was wondering if there was any PHP library that helps with this, preferably in a similar way to jQuery: retrieving and manipulating element attributes, selecting all the attributes with a given class, etc.
you can use phpquery or querypath. Here is a comprehensive tutorial about querypath.
There is a Dom Parser in PHP :
http://php.net/manual/en/class.domdocument.php
Sounds like you should be manipulating the HTML as a DOMdocument and using XPath (quite similar to jQuery selectors) to select the nodes.
Next to what silent answered, there is also FluentDOM which is not exactly jQuery mimicking, but provides fluent interfaces based on DomDocument
Docs.
精彩评论