小试QueryPath,一个实现了不少jQuery接口的PHP类库
2011-11-12 09:15
344 查看
简介:这是小试QueryPath,一个实现了不少jQuery接口的PHP类库的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=338996' scrolling='no'>很想写一个PHP的jQuery,但是自己精力与能力有限,于是Google一下,找到 QueryPath。
其实前几天已经找到一个,叫 simple_html_dom (SourceForge下载),不到1000行代码,很简单。有兴趣就下载看看。
基本使用方法:
require 'src/QueryPath/QueryPath.php';
// 解释HTML为DOM
qp('<html>...</html>');
// 或者加载文件
qp('http://www.google.com.hk/index.html');如果 qp的第一个参数是 url(包括http、file),则需要以html或htm为后缀名,否则当作XML来解释,通常会解释失败,并抛出 QueryPathExtension 异常,这应该说是一个缺陷,2.1版本的代码在QueryPath.php的3903-4010行。
有了qp返回的对象,我们就可以用 PHP 以 jQuery 类似的方法来操作DOM,如选择节点,可以用CSS3选择器、parent/top/children等函数。
下载是官方手册上的一个快速入门的例子 :
<?php
require_once '../src/QueryPath/QueryPath.php';
// Begin with an HTML stub document (XHTML, actually), and navigate to the title.
qp(QueryPath::HTML_STUB, 'title')
// Add some text to the title
->text('Example of QueryPath.')
// Now look for the <body> element
->find(':root body')
// Inside the body, add a title and paragraph.
->append('<h1>This is a test page</h1><p>Test text</p>')
// Now we select the paragraph we just created inside the body
->children('p')
// Add a 'class="some-class"' attribute to the paragraph
->attr('class', 'some-class')
// And add a style attribute, too, setting the background color.
->css('background-color', '#eee')
// Now go back to the paragraph again
->parent()
// Before the paragraph and the title, add an empty table.
->prepend('<table id="my-table"></table>')
// Now let's go to the table...
->find('#my-table')
// Add a couple of empty rows
->append('<tr></tr><tr></tr>')
// select the rows (both at once)
->children()
// Add a CSS class to both rows
->addClass('table-row')
// Now just get the first row (at position 0)
->eq(0)
// Add a table header in the first row
->append('<th>This is the header</th>')
// Now go to the next row
->next()
// Add some data to this row
->append('<td>This is the data</td>')
// Write it all out as HTML
->writeHTML();
?>详细请参考其官网及API手册(包含在源码中):http://querypath.org/
QueryPath的基本特征:http://querypath.org/node/2
爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具
http://biancheng.dnbcw.info/php/338996.html pageNo:8
class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=338996' scrolling='no'>很想写一个PHP的jQuery,但是自己精力与能力有限,于是Google一下,找到 QueryPath。
其实前几天已经找到一个,叫 simple_html_dom (SourceForge下载),不到1000行代码,很简单。有兴趣就下载看看。
基本使用方法:
require 'src/QueryPath/QueryPath.php';
// 解释HTML为DOM
qp('<html>...</html>');
// 或者加载文件
qp('http://www.google.com.hk/index.html');如果 qp的第一个参数是 url(包括http、file),则需要以html或htm为后缀名,否则当作XML来解释,通常会解释失败,并抛出 QueryPathExtension 异常,这应该说是一个缺陷,2.1版本的代码在QueryPath.php的3903-4010行。
有了qp返回的对象,我们就可以用 PHP 以 jQuery 类似的方法来操作DOM,如选择节点,可以用CSS3选择器、parent/top/children等函数。
下载是官方手册上的一个快速入门的例子 :
<?php
require_once '../src/QueryPath/QueryPath.php';
// Begin with an HTML stub document (XHTML, actually), and navigate to the title.
qp(QueryPath::HTML_STUB, 'title')
// Add some text to the title
->text('Example of QueryPath.')
// Now look for the <body> element
->find(':root body')
// Inside the body, add a title and paragraph.
->append('<h1>This is a test page</h1><p>Test text</p>')
// Now we select the paragraph we just created inside the body
->children('p')
// Add a 'class="some-class"' attribute to the paragraph
->attr('class', 'some-class')
// And add a style attribute, too, setting the background color.
->css('background-color', '#eee')
// Now go back to the paragraph again
->parent()
// Before the paragraph and the title, add an empty table.
->prepend('<table id="my-table"></table>')
// Now let's go to the table...
->find('#my-table')
// Add a couple of empty rows
->append('<tr></tr><tr></tr>')
// select the rows (both at once)
->children()
// Add a CSS class to both rows
->addClass('table-row')
// Now just get the first row (at position 0)
->eq(0)
// Add a table header in the first row
->append('<th>This is the header</th>')
// Now go to the next row
->next()
// Add some data to this row
->append('<td>This is the data</td>')
// Write it all out as HTML
->writeHTML();
?>详细请参考其官网及API手册(包含在源码中):http://querypath.org/
QueryPath的基本特征:http://querypath.org/node/2
爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具
http://biancheng.dnbcw.info/php/338996.html pageNo:8
相关文章推荐
- 小试QueryPath,一个实现了不少jQuery接口的PHP类库
- 事件代理总结: 已经有一些使用主流类库的事件代理示例出现了,比如说jQuery、Prototype以及Yahoo! UI。你也可以找到那些不用任何类库的例子,比如说Usable Type blog上的这一个。一旦需要的话,事件代理将是你工具箱里的一件得心应手的工具,而且它很容易实现。
- jquery中用$.ajax实现注册(html、jquery、php、接口文档)、ajax验证用户提交数据
- 如何使用jQuery+PHP+MySQL来实现一个在线测试项目
- 如何使用jQuery+PHP+MySQL来实现一个在线测试项目
- 如何使用jQuery+PHP+MySQL来实现一个在线测试项目
- php接口技术实现一个简单的多态应用实例
- jquery和php实现同一个页面传值
- 【转】jQuery+Ajax+PHP登录实例 一个简单的用Jquery中ajax方法登录的例子
- PHP+Mysql+jQuery实现地图区域数据统计-载入数据
- 基于jQuery与PHP实现Ajax长轮询(LongPoll)
- php+jquery+html实现点击不刷新加载更多的实例代码
- 编写一个Book类,该类至少有name和price两个属性。该类要实现Comparable接口,在接口的compareTo()方法中规定两个Book类实例的大小关系为二者的price属性的大小关系。在
- PHP实现分页的一个示例
- PHP+MySql+jQuery实现的“顶”和“踩”投票功能
- 使用array和list实现在php中一个函数同时返回多个值
- 又一个php 分页类实现代码
- 用Jquery实现的一个Table的帮助js
- C#嵌入x86汇编——一个GPIO接口的实现
- PHP实现预留SessionHandlerInterface接口从而将session存储到数据库中