bscheshir / phpquery
PHP5.3+ 命名空间版本的phpQuery,增强CSS支持
0.9.8.1
2016-10-14 06:56 UTC
Requires
- php: >=5.3.3
- sabberworm/php-css-parser: 5.1.*
This package is not auto-updated.
Last update: 2024-09-28 19:58:17 UTC
README
此分支的基本用法
// This gives you the phpQuery object as normally used. use PhpQuery\PhpQuery as phpQuery; // This creates the pq() function in your namespace. PhpQuery::use_function(__NAMESPACE__); // This creates the pq() function in the global namespace. PhpQuery::use_function();
关于此分支
此分支包含一些现代化改进
- 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选择器驱动的服务器端、链式Document Object Model (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>
=======
- 合并 https://github.com/kevee/phpquery/tree/phpquery-css 与 https://github.com/electrolinux/phpquery
- 从本仓库中移除了CSSParser,并通过composer引入
- 添加 PhpQuery\ 命名空间
- 调整文件夹结构以反映PSR-4的使用
- 纠正了单元测试并将其集成到travis-ci
更新README以反映项目状态。
除了这些调整,此项目将进行最小维护。有关更多信息以及分支历史,我强烈建议您查阅https://github.com/electrolinux/phpquery README。
非常类似的项目
查看QueryPath,这是一个更活跃的项目,也致力于为PHP复制jQuery语法。
我的首选替代方案
市面上有几种phpQuery的替代方案。虽然其中一些采用了健康的使用率,但我正在寻找一个利用SimpleXML并专注于PHP用例的库,而不是从头开始构建所有功能并添加不必要的方法和选择器,仅仅为了jQuery语义的完整性。最终,我选择了启动一个项目,该项目试图成为一个以PHP为中心的轻量级SimpleXML包装器。有关QuipXml的更多信息了解更多关于QuipXml。