bscheshir/phpquery

PHP5.3+ 命名空间版本的phpQuery,增强CSS支持

0.9.8.1 2016-10-14 06:56 UTC

This package is not auto-updated.

Last update: 2024-09-28 19:58:17 UTC


README

Build Status

此分支的基本用法

// 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();

关于此分支

此分支包含一些现代化改进

我查看过的github仓库

手册

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>

=======

  1. 合并 https://github.com/kevee/phpquery/tree/phpquery-csshttps://github.com/electrolinux/phpquery
  2. 从本仓库中移除了CSSParser,并通过composer引入
  3. 添加 PhpQuery\ 命名空间
  4. 调整文件夹结构以反映PSR-4的使用
  5. 纠正了单元测试并将其集成到travis-ci

更新README以反映项目状态。

除了这些调整,此项目将进行最小维护。有关更多信息以及分支历史,我强烈建议您查阅https://github.com/electrolinux/phpquery README。

非常类似的项目

查看QueryPath,这是一个更活跃的项目,也致力于为PHP复制jQuery语法。

我的首选替代方案

市面上有几种phpQuery的替代方案。虽然其中一些采用了健康的使用率,但我正在寻找一个利用SimpleXML并专注于PHP用例的库,而不是从头开始构建所有功能并添加不必要的方法和选择器,仅仅为了jQuery语义的完整性。最终,我选择了启动一个项目,该项目试图成为一个以PHP为中心的轻量级SimpleXML包装器。有关QuipXml的更多信息了解更多关于QuipXml。