Home > Backend Development > PHP Tutorial > php仿jQuery统制dom | php采集

php仿jQuery统制dom | php采集

WBOY
Release: 2016-06-13 13:04:41
Original
775 people have browsed it

php仿jQuery控制dom | php采集
详细情况,各位可以自行下载附件运行体验一下。
有段时间在制作PHP采集相关的程序,突然搜索到有一个比较好用的,外国人开发的类包,名叫"phpQuery",是否听这个名字就已经感觉很熟悉呢,这是一个PHP仿jQuery控制dom的好工作,利用PHP做采集必不可少的利器。

先贴出dome的部分代码:

require('phpQuery/phpQuery.php');
$doc['ul > li']
	->addClass('my-new-class')
	->filter(':last')
		->addClass('last-li')
		->toReference($li);

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');
}
Copy after login


希望大家可以喜欢
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template