phptek / phpquery
phpQuery是一个基于jQuery JavaScript库的,服务器端、可链式操作、CSS3选择器驱动的文档对象模型(DOM)API
1.0.2
2022-08-21 10:51 UTC
This package is auto-updated.
Last update: 2024-09-22 21:37:16 UTC
README
注意: 我已经多年没有使用这个包了,最近才看了代码:这很可怕,有很多错误和未完成的地方。请不要在任何生产服务器上使用它!
我的意图是让它容易集成到不同的项目中,因此可在packagist上使用。我在这里收集了一些修复和新功能,并且会继续在github上寻找关于phpQuery的新内容
我集成的github仓库
- https://github.com/ralph-tice/phpquery(一个提交:添加了WebBrowser->browserDownload)
- https://github.com/aptivate/phpquery(三个提交)
- https://github.com/panrafal/phpquery(移除zend)
我查看过的github仓库
- https://github.com/denis-isaev/phpquery
- https://github.com/r-sal/phpquery
- https://github.com/damien-list/phpquery-1
- https://github.com/nev3rm0re/phpquery
- https://github.com/Aurielle/phpquery
- https://github.com/kevee/phpquery(包含php-css-parser)
- https://github.com/lucassouza1/phpquery
手册
fmorrow README.md的摘录
什么是phpQuery?
以下引用phpQuery项目文档(最初由Tobiasz Cudnik构思和开发,可在Google Code和Github上找到)
phpQuery是一个基于jQuery JavaScript库的,服务器端、可链式操作、CSS3选择器驱动的文档对象模型(DOM)API。
该库是用PHP5编写的,并提供了额外的命令行界面(CLI)。
示例用法
(从http://code.google.com/p/phpquery/wiki/Basics复制)
完整工作示例
<?php include 'phpQuery-onefile.php'; $file = 'test.html'; // see below for source // loads the file // basically think of your php script as a regular HTML page running client side with jQuery. This loads whatever file you want to be the current page phpQuery::newDocumentFileHTML($file); // Once the page is loaded, you can then make queries on whatever DOM is loaded. // This example grabs the title of the currently loaded page. $titleElement = pq('title'); // in jQuery, this would return a jQuery object. I'm guessing something similar is happening here with pq. // You can then use any of the functionality available to that pq object. Such as getting the innerHTML like I do here. $title = $titleElement->html(); // And output the result echo '<h2>Title:</h2>'; echo '<p>' . htmlentities( $title) . '</p>'; ?>
====
test.html的源代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Hello World!</title> </head> <body> </body> </html>