PHP 中是否有 JQuery DOM 操纵器/CSS 选择器等效类?

发布于 2024-08-30 03:01:00 字数 691 浏览 10 评论 0原文

我知道我可以使用 DOMDocumentDOMXPath 来操作 XML 文件。但是,我真的很喜欢 JQuery,如果 PHP 世界中有类似 JQuery 的东西可以用于服务器端 DOM 操作,那就太好了。

注意:我只对如何做到这一点感兴趣 JQuery 选择并操作 DOM,而不是全部 JQuery 的其他部分(我猜 你可以只说 Pop 和 Sizzle 部分)。


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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏见 2024-09-06 03:01:00

您可以使用 phpQuery

它的描述如下:phpQuery 是一个 PHP5 服务器端,可链接,基于 jQuery JavaScript 库的 CSS3 选择器驱动的文档对象模型 (DOM) API。

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.

孤独岁月 2024-09-06 03:01:00

好吧,排除所有 JavaScript 特定的东西,你只剩下 CSS 选择器引擎:

http://framework.zend.com/manual/en/zend.dom.query.html

享受吧:)

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

乱世争霸 2024-09-06 03:01:00

是的, HtmlPageDom 正是根据您的要求编写的。

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

怪我闹别瞎闹 2024-09-06 03:01:00

@retro:他要求的是像 sizzle 这样的库,它使用 PHP 作为语言而不是 javascript,你所说的“无需更改即可编写”是错误的,它只是代码,你可以尽可能多地编写它想。

然而,我认为问题是,在浏览器中运行的 javascript 可以为您提供访问 DOM 系统的+1,这可以帮助您自动创建大量 dom 节点/html 节点,而无需自己创建它们。

在 php 中,DOM 很痛苦,jquery 很高兴地将其隐藏起来,并且由于 javascript 的工作方式与 PHP 不同,它可以毫不费力地做到这一点,但是 PHP 无法访问浏览器 DOM 并且具有不同的操作方法,它的作用要大得多痛苦。

这并不是说这是不可能的,因为它是,只是它并不那么容易,有时当似乎没有明确的原因时它会有所不同,我相信这可能是 PHP DOM 内部使用 libXML 或类似的东西并且在内部公开了太多该库的内容,因此 PHP 因 C 库语义而变得混乱。

我认为你应该看看 phpQuery(https://github.com/TobiaszCudnik/phpquery),或者更好的、正在积极开发的 QueryPath (http://querypath.org)。

然而,不要指望它们像 javascript jquery 库一样简单,因为不幸的是,它不是......

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文