phpQuery下载—包含官方完整使用文档

模板网 2014-10-07

phpQuery下载—包含官方完整使用文档。phpQuery是一个类似jQuery的php网页采集类库,使用方法非常简单。

下载地址:phpQuery下载—包含官方完整使用文档

官方下载地址:https://code.google.com/p/phpquery/

下载压缩包截图:

phpQuery下载—包含官方完整使用文档

官方提供的demo代码:

复制代码 代码如下:
<?php
require('phpQuery/phpQuery.php');
 
// INITIALIZE IT
// phpQuery::newDocumentHTML($markup);
// phpQuery::newDocumentXML();
// phpQuery::newDocumentFileXHTML('test.html');
// phpQuery::newDocumentFilePHP('test.php');
// phpQuery::newDocument('test.xml', 'application/rss+xml');
// this one defaults to text/html in utf8
$doc = phpQuery::newDocument('<div/>');
 
// FILL IT
// array syntax works like ->find() here
$doc['div']->append('<ul></ul>');
// array set changes inner html
$doc['div ul'] = '<li>1</li> <li>2</li> <li>3</li>';
 
// MANIPULATE IT
$li = null;
// almost everything can be a chain
$doc['ul > li']
->addClass('my-new-class')
->filter(':last')
->addClass('last-li')
// save it anywhere in the chain
->toReference($li);
 
// SELECT DOCUMENT
// pq(); is using selected document as default
phpQuery::selectDocument($doc);
// documents are selected when created or by above method
// query all unordered lists in last selected document
$ul = pq('ul')->insertAfter('div');
 
// ITERATE IT
// all direct LIs from $ul
foreach($ul['> li'] as $li) {
// iteration returns PLAIN dom nodes, NOT phpQuery objects
$tagName = $li->tagName;
$childNodes = $li->childNodes;
// so you NEED to wrap it within phpQuery, using pq();
pq($li)->addClass('my-second-new-class');
}
 
// PRINT OUTPUT
// 1st way
print phpQuery::getDocument($doc->getDocumentID());
// 2nd way
print phpQuery::getDocument(pq('div')->getDocumentID());
// 3rd way
print pq('div')->getDocument();
// 4th way
print $doc->htmlOuter();
// 5th way
print $doc;
// another...
print $doc['ul'];

 

相关文章

  1. 超简单的php在线解压zip文件代码

    超简单的php在线解压zip文件代码 代码如下: unzip.php 复制代码 代码如下: ?php set_time_limit(0); $zip = new ZipArchive(); if($zip-open(a.zip)===true){ $zip-extractTo(./); echo Ok; }else{ echo Failed; } ? 使用方法,讲代码保存为unzip.php文件传

  2. 使用phpQuery简单抓取百度搜索结果的代码

    使用phpQuery制作了一个简单的抓取百度搜索结果的代码。 代码如下: 复制代码 代码如下: style body {font-family: arial;} a em {text-decoration: underline;} em {font-style: normal;color: #C00;} /style ?php $kw = empty($_GET[kw])?text:$_GET[kw];

  3. PHP在线清除文件BOM工具

    在utf-8编码文件中BOM在文件头部,占用三个字节,用来标示该文件属于utf-8编码,现在已经有很多软件识别bom头,但是还有些不能识别bom头,比如PHP就不能识别bom头,这也是用记事本编辑utf-8编码后执行就会出错的原因了。 下面医疗模板库为大家提供一个PHP在

  4. PHP date函数输出时间少8小时的解决方法

    使用某些PHP服务器套件开发PHP程序的时候,调用date函数输出时间会少8小时,下面提供一个解决的方法。

  5. MySQL在线管理工具Adminer.php单文件轻量级功能强大

    Adminer(原名phpMinAdmin)是用PHP编写的一个全功能的数据库管理工具。相比phpMyAdmin,它包含一个文件可以部署到目标服务器。管理可用于MySQL、PostgreSQL SQLite,MS SQL,甲骨文,SimpleDB,Elasticsearch MongoDB。

随机推荐

  1. 超简单的php在线解压zip文件代码

    超简单的php在线解压zip文件代码 代码如下: unzip.php 复制代码 代码如下: ?php set_time_limit(0); $zip = new ZipArchive(); if($zip-open(a.zip)===true){ $zip-extractTo(./); echo Ok; }else{ echo Failed; } ? 使用方法,讲代码保存为unzip.php文件传

  2. 使用phpQuery简单抓取百度搜索结果的代码

    使用phpQuery制作了一个简单的抓取百度搜索结果的代码。 代码如下: 复制代码 代码如下: style body {font-family: arial;} a em {text-decoration: underline;} em {font-style: normal;color: #C00;} /style ?php $kw = empty($_GET[kw])?text:$_GET[kw];

  3. PHP在线清除文件BOM工具

    在utf-8编码文件中BOM在文件头部,占用三个字节,用来标示该文件属于utf-8编码,现在已经有很多软件识别bom头,但是还有些不能识别bom头,比如PHP就不能识别bom头,这也是用记事本编辑utf-8编码后执行就会出错的原因了。 下面医疗模板库为大家提供一个PHP在

  4. PHP date函数输出时间少8小时的解决方法

    使用某些PHP服务器套件开发PHP程序的时候,调用date函数输出时间会少8小时,下面提供一个解决的方法。

  5. MySQL在线管理工具Adminer.php单文件轻量级功能强大

    Adminer(原名phpMinAdmin)是用PHP编写的一个全功能的数据库管理工具。相比phpMyAdmin,它包含一个文件可以部署到目标服务器。管理可用于MySQL、PostgreSQL SQLite,MS SQL,甲骨文,SimpleDB,Elasticsearch MongoDB。