Is there a JQuery DOM manipulator/CSS selector equivalent class in PHP?

爱⌒轻易说出口 提交于 2019-12-21 21:38:58

问题


I know that I can use DOMDocument and DOMXPath 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.

回答1:


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 :)




回答2:


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.




回答3:


Yes, HtmlPageDom is written exactly for what you are asking.




回答4:


@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.....



来源:https://stackoverflow.com/questions/2722109/is-there-a-jquery-dom-manipulator-css-selector-equivalent-class-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!