I know that I can use DOMDocument and D开发者_如何学COMXPath to manipulate XML files. But, I really love JQuery, and it would be great if there was something more like JQuery in the PHP world that I could use for sever side DOM manipulation.
NOTE: I'm only interested here in how JQuery Selects and Manipulates the DOM, not all the other parts of JQuery (I guess you can say just the Pop and the Sizzle parts).
Update: It looks like there is an equivalent for the selector functions, but as far as the manipulation functions I guess I have to stick with DOMDocument.
You can use phpQuery
It describes itself as follows: phpQuery is a PHP5 server-side, chainable, CSS3 selector driven Document Object Model (DOM) API based on the jQuery JavaScript Library.
Well, excluding all the JavaScript specific stuff you're left with a CSS selector engine:
http://framework.zend.com/manual/en/zend.dom.query.html
Enjoy :)
Yes, HtmlPageDom is written exactly for what you are asking.
@retro: what he is asking for is a library like sizzle which works using PHP as a language instead of javascript, what you said about "no change to write it" is wrong, it's just code, you can write it as much as you want.
however, the problem I believe is that javascript running inside a browser gives you a +1 up on having access to a DOM system which can help you a lot in creating a lot of dom nodes / html nodes automatically without having to do them yourself.
in php, the DOM is just painful, jquery happily hides this away and as javascript works differently than PHP, it can do that without much effort, however PHP not having access to the browser DOM and having a different method of operation, it's much more painful.
thats not to say it's impossible, because it is, it's just that it's not as easy and sometimes it's different when there doesn't seem to be a clear reason why, I believe it might be that the PHP DOM internally uses libXML or something similar and exposes far too much of that library internally so PHP gets cluttered up with the C library semantics.
I think you should look at phpQuery(https://github.com/TobiaszCudnik/phpquery), or even better and in active development, QueryPath (http://querypath.org).
however, don't expect them to be as easy as the javascript jquery library, cause it's not, unfortunately.....
精彩评论