検索

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 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:
复制代码 代码如下:




Untitled

Hello World


Most of that HTML comes from the QueryPath::HTML_STUB. All we did was add the Hello World text inside of the 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.
复制代码 代码如下:
/**
* Using QueryPath.
*
* This file contains an example of how QueryPath can be used
* to generate web pages.
* @package QueryPath
* @subpackage Examples
* @author M Butcher
* @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 element
->find(':root body')
// Inside the body, add a title and paragraph.
->append('

This is a test page

Test text

')
// 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('
')
// Now let's go to the table...
->find('#my-table')
// Add a couple of empty rows
->append(' ')
// 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('This is the header')
// Now go to the next row
->next()
// Add some data to this row
->append('This is the data')
// Write it all out as HTML
->writeHTML();
?>

The code above produces the following HTML:
复制代码 代码如下:




Example of QueryPath.





This is the header
This is the data

This is a test page


Test text




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 它吧~~!
声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
誇大広告を超えて:今日のPHPの役割の評価誇大広告を超えて:今日のPHPの役割の評価Apr 12, 2025 am 12:17 AM

PHPは、特にWeb開発の分野で、最新のプログラミングで強力で広く使用されているツールのままです。 1)PHPは使いやすく、データベースとシームレスに統合されており、多くの開発者にとって最初の選択肢です。 2)動的コンテンツ生成とオブジェクト指向プログラミングをサポートし、Webサイトを迅速に作成および保守するのに適しています。 3)PHPのパフォーマンスは、データベースクエリをキャッシュおよび最適化することで改善でき、その広範なコミュニティと豊富なエコシステムにより、今日のテクノロジースタックでは依然として重要になります。

PHPの弱い参照は何ですか、そしていつ有用ですか?PHPの弱い参照は何ですか、そしていつ有用ですか?Apr 12, 2025 am 12:13 AM

PHPでは、弱い参照クラスを通じて弱い参照が実装され、ガベージコレクターがオブジェクトの回収を妨げません。弱い参照は、キャッシュシステムやイベントリスナーなどのシナリオに適しています。オブジェクトの生存を保証することはできず、ごみ収集が遅れる可能性があることに注意する必要があります。

PHPで__invoke Magicメソッドを説明してください。PHPで__invoke Magicメソッドを説明してください。Apr 12, 2025 am 12:07 AM

\ _ \ _ Invokeメソッドを使用すると、オブジェクトを関数のように呼び出すことができます。 1。オブジェクトを呼び出すことができるように\ _ \ _呼び出しメソッドを定義します。 2。$ obj(...)構文を使用すると、PHPは\ _ \ _ Invokeメソッドを実行します。 3。ロギングや計算機、コードの柔軟性の向上、読みやすさなどのシナリオに適しています。

同時性については、PHP 8.1の繊維を説明します。同時性については、PHP 8.1の繊維を説明します。Apr 12, 2025 am 12:05 AM

繊維はPhp8.1で導入され、同時処理機能が改善されました。 1)繊維は、コルーチンと同様の軽量の並行性モデルです。 2)開発者がタスクの実行フローを手動で制御できるようにし、I/O集約型タスクの処理に適しています。 3)繊維を使用すると、より効率的で応答性の高いコードを書き込むことができます。

PHPコミュニティ:リソース、サポート、開発PHPコミュニティ:リソース、サポート、開発Apr 12, 2025 am 12:04 AM

PHPコミュニティは、開発者の成長を支援するための豊富なリソースとサポートを提供します。 1)リソースには、公式のドキュメント、チュートリアル、ブログ、LaravelやSymfonyなどのオープンソースプロジェクトが含まれます。 2)StackOverFlow、Reddit、およびSlackチャネルを通じてサポートを取得できます。 3)開発動向は、RFCに従うことで学ぶことができます。 4)コミュニティへの統合は、積極的な参加、コード共有への貢献、および学習共有への貢献を通じて達成できます。

PHP対Python:違いを理解しますPHP対Python:違いを理解しますApr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHPは、シンプルな構文と高い実行効率を備えたWeb開発に適しています。 2。Pythonは、簡潔な構文とリッチライブラリを備えたデータサイエンスと機械学習に適しています。

PHP:それは死にかけていますか、それとも単に適応していますか?PHP:それは死にかけていますか、それとも単に適応していますか?Apr 11, 2025 am 12:13 AM

PHPは死にかけていませんが、常に適応して進化しています。 1)PHPは、1994年以来、新しいテクノロジーの傾向に適応するために複数のバージョンの反復を受けています。 2)現在、電子商取引、コンテンツ管理システム、その他の分野で広く使用されています。 3)PHP8は、パフォーマンスと近代化を改善するために、JITコンパイラおよびその他の機能を導入します。 4)Opcacheを使用してPSR-12標準に従って、パフォーマンスとコードの品質を最適化します。

PHPの未来:適応と革新PHPの未来:適応と革新Apr 11, 2025 am 12:01 AM

PHPの将来は、新しいテクノロジーの傾向に適応し、革新的な機能を導入することで達成されます。1)クラウドコンピューティング、コンテナ化、マイクロサービスアーキテクチャに適応し、DockerとKubernetesをサポートします。 2)パフォーマンスとデータ処理の効率を改善するために、JITコンパイラと列挙タイプを導入します。 3)パフォーマンスを継続的に最適化し、ベストプラクティスを促進します。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

PhpStorm Mac バージョン

PhpStorm Mac バージョン

最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール

MantisBT

MantisBT

Mantis は、製品の欠陥追跡を支援するために設計された、導入が簡単な Web ベースの欠陥追跡ツールです。 PHP、MySQL、Web サーバーが必要です。デモおよびホスティング サービスをチェックしてください。

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境