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. 使用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];

  2. php判断一个页面是否被删除判断返回404

    复制代码 代码如下: ?php function get404($urla){ $headers = get_headers($urla); $htt = $headers[3]; $silingsi = 404; if(stripos($htt,$silingsi,0)== false){ $shoulu = 正常; return $shoulu; break; }else{ $shoulu = 404; return $shoulu; break;

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

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

  4. php获取访客所在城市名称代码

    php获取访客所在城市名称代码,采用纯真QQ IP数据库,想要使用最新版IP数据库可到纯真官网获

  5. 后盾网ThinkPHP教程许愿墙及后台管理模版

    后盾网ThinkPHP教程许愿墙及后台管理模版,在网上找了一圈没找到,后来在论坛里给找到了,分享出来和大家一起学习。 打包下载: 后盾网ThinkPHP教程许愿墙及后台管理模版 ─许愿墙及后台管理模版 ├─Admin │ │ .DS_Store │ │ index.html │ │ login.ht

随机推荐

  1. 使用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];

  2. php判断一个页面是否被删除判断返回404

    复制代码 代码如下: ?php function get404($urla){ $headers = get_headers($urla); $htt = $headers[3]; $silingsi = 404; if(stripos($htt,$silingsi,0)== false){ $shoulu = 正常; return $shoulu; break; }else{ $shoulu = 404; return $shoulu; break;

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

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

  4. php获取访客所在城市名称代码

    php获取访客所在城市名称代码,采用纯真QQ IP数据库,想要使用最新版IP数据库可到纯真官网获

  5. 后盾网ThinkPHP教程许愿墙及后台管理模版

    后盾网ThinkPHP教程许愿墙及后台管理模版,在网上找了一圈没找到,后来在论坛里给找到了,分享出来和大家一起学习。 打包下载: 后盾网ThinkPHP教程许愿墙及后台管理模版 ─许愿墙及后台管理模版 ├─Admin │ │ .DS_Store │ │ index.html │ │ login.ht