atofighi / phpquery
phpQuery 是一个基于 jQuery JavaScript 库的、链式调用、CSS3 选择器的服务器端 DOM API
2.0.1
2015-11-10 17:41 UTC
This package is not auto-updated.
Last update: 2024-09-14 17:43:03 UTC
README
来源: https://github.com/bariew/phpquery
什么是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>