2

有没有人有关于使用 phpQuery 和 CodeIgniter 的操作方法和教程?

我问是因为我想操纵某些 css 属性并换出某些 css 值。我本可以使用 JavaScript 来做到这一点,但是混合 PHP 和 JavaScript 很困难,所以这意味着要找到一种方法来操作 HTML 和 css 来做到这一点。无论如何,希望大家能提供帮助。

所以我希望加载 phpquery 并像任何其他库一样使用它

$this->load->libary('phpquery');
$this->phpquery->pq('div > p')->findall();
4

2 回答 2

4

onefile通过使用phpQuery 版本作为助手,我让 phpQuery 在我当前的 CodeIgniter 项目中工作。

安装

  1. 下载phpQuery-onefile.zip
  2. 提取并复制 phpQuery-onefile.php 到/your/ci/proj/application/helpers/phpQuery_helper.php
  3. 像普通助手一样加载它。

用法

这是我工作的一个非常基本的例子。

//to load in a controller
$this->load->helper('phpQuery');

//I'm using phpQuery in one of my libraries. So, load like this..
$ci =& get_instance();
$ci->load->helper('phpQuery');

//now use phpQuery like normal.  
phpQuery::newDocumentHTML('<div id="test">This is a test.</div');

$testElement = pq('#test');

echo $testElement->html(); //This is a test.


或者

您也可以只使用普通的旧include_once('path/to/phpQuery-onefile.php');

于 2012-11-01T23:57:05.763 回答
1

你试过 PHP 的 DomDocument 类吗?

http://php.net/manual/en/class.domdocument.php

这应该有点用吧?

于 2012-07-19T14:13:46.233 回答