A QueryPath Tutorial(一個簡 " /> 超碰在线vip,老湿司午夜爽爽影院榴莲视频,欧洲最大无人区免费高清完整版

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

QueryPath PHP 中的jQuery

官方主頁  http://querypath.org/

QP API 手冊  http://api.querypath.org/docs/QueryPath(QP)庫 在 php 中實現了類似于 jQuery 的效果,用它還可以方便地處理 XML HTML...功能太強大了!!!

A QueryPath Tutorial(一個簡易說明)
QueryPath makes use of method chaining to provide a concise suite of tools for manipulating a DOM.
The basic principle of method chaining is that each method returns an object upon which additional methods can be called. In our case, the QueryPath object usually returns itself.
Let's take a look at an example to illustrate:
$qp = qp(QueryPath::HTML_STUB); // Generate a new QueryPath object.(創建一個 QP 對象)
$qp2 = $qp->find('body'); // Find the body tag.(找到 "body" 標簽)
// Now the surprising part:(請看下面讓你驚奇的地方)
if ($qp === $qp2) {
// This will always get printed.(它總是會這樣輸出)
print "MATCH";
}
Why does $qp always equal $qp2? Because the find() function does all of its data gathering and then returns the QueryPath object.
This might seem esoteric, but it all has a very practical rationale. With this sort of interface, we can chain lots of methods together:
(你可以向使用 jQuery 一樣來連綴方法)
qp(QueryPath::HTML_STUB)->find('body')->text('Hello World')->writeHTML();
In this example, we have four method calls:
qp(QueryPath::HTML_STUB): Create a new QueryPath object and provide it with a stub of an HTML document. This returns the QueryPath object.
find('body'): This searches the QueryPath document looking for an element named 'body'. That element is, of course, the <body></body> portion of the HTML document. When it finds the body element, it keeps an internal pointer to that element, and it returns the QueryPath object (which is now wrapping the body element).
text('Hello World'): This function takes the current element(s) wrapped by QueryPath and adds the text Hello World. As you have probably guessed, it, too, returns a QueryPath object. The object will still be pointing to the body element.
writeHTML(): The writeHTML() function prints out the entire document. This is used to send the HTML back to the client. You'll never guess what this function returns. Okay, you guessed it. QueryPath.
So at the end of the chain above, we would have created a document that looks something like this:
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<title>Untitled</title>
</head>
<body>Hello World</body>
</html>

Most of that HTML comes from the QueryPath::HTML_STUB. All we did was add the Hello World text inside of the <body></body> tags.
Not all QueryPath functions return QueryPath objects. Some tools need to return other data. But those functions are well-documented in the included documentation.
These are the basic principles behind QueryPath. Now let's take a look at a larger example that exercises more of the QueryPath API.
A Longer Example
This example illustrates various core features of QueryPath.
In this example, we use some of the standard QueryPath functions (most of them implementing the jQuery interface) to build a new web page from scratch.
Each line of the code has been commented individually. The output from this is shown in a separate block beneath.
復制代碼 代碼如下:
<?php
/**
* Using QueryPath.
*
* This file contains an example of how QueryPath can be used
* to generate web pages.
* @package QueryPath
* @subpackage Examples
* @author M Butcher <[email protected]>
* @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
*/
// Require the QueryPath core.
require_once '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();
?>

The code above produces the following HTML:
復制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<title>Example of QueryPath.</title>
</head>
<body>
<table id="my-table">
<tr class="table-row"><th>This is the header</th></tr>
<tr class="table-row"><td>This is the data</td></tr>
</table>
<h1>This is a test page</h1>
<p class="some-class" style="background-color: #eee">Test text</p></body>
</html>

Now you should have an idea of how QueryPath works. Grab a copy of the library and try it out! Along with the source code, you will get a nice bundle of HTML files that cover every single public function in the QueryPath library (no kidding). There are more examples there, too.
不錯的東東!趕緊 Grab 它吧~~!

php技術QueryPath PHP 中的jQuery,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 55夜色66夜亚洲精品播放 | 久久精品动漫网一区二区 | 精品久久久久久久久免费影院 | 色婷婷99综合久久久精品 | 国产亚洲欧洲日韩在线观看 | 苍井空小公主qvod | 国产欧美无码亚洲毛片 | www.av天堂网.com| 国产一级特黄a大片99 | 天天影视色欲 影视 | 美女露出撒尿的部位 | 亚洲 欧美 制服 视频二区 | 亚洲AV无码乱码A片无码蜜桃 | 日本一卡精品视频免费 | 国产成人拍精品免费视频爱情岛 | 国自产精品手机在线视频 | 亚色九九九全国免费视频 | 一区二区三区毛AAAA片特级 | 欧美亚洲精品真实在线 | 久久学生精品国产自在拍 | 国产1000部成人免费视频 | 国产1769一七六九视频在线 | 精品久久久无码21P发布 | 中文字幕 人妻熟女 | 久久夜色噜噜噜亚洲AV0000 | 亚洲AV久久无码精品九九软件 | 亚洲精品国产在线观看 | 国产精品7777人妻精品冫 | 伊人网伊人网 | 欧美日韩亚洲中字二区 | 边摸边吃奶边做激情叫床视 | 伊人精品久久久大香线蕉99 | 我的家庭女教师 | 青青青手机视频 | 久久精品免费电影 | 色99久久久久高潮综合影院 | 边做边爱BD免费看片 | 美女国产毛片A区内射 | 亚洲AV无码一区二区三区牛牛 | 亚洲精品无夜久久久久久久久 | 伊人久久综在合线亚洲 |