简介
如何在php中方便地解析html代码,估计是每个phper都会遇到的问题。用phpQuery就可以让php处理html代码像jQuery一样方便。
项目地址:https://code.google.com/p/phpquery/
github地址:https://github.com/TobiaszCudnik/phpquery
DEMO
下载库文件:https://code.google.com/p/phpquery/downloads/list
我下的是onefile版:phpQuery-0.9.5.386-onefile.zip
官方demo:https://code.google.com/p/phpquery/source/browse/branches/dev/demo.php
然后在项目中引用。
html文件test.html:
复制代码 代码如下:
<div class="thumb" id="Thumb-13164-3640" style="position: absolute; left: 0px; top: 0px;">
<a href="/Spiderman-City-Drive">
<img src="/UploadFiles/2021-04-02/Spiderman-City-Drive.jpg">
<span class="GameName" id="GameName-13164-3640" style="display: none;">Spiderman City Drive</span>
<span class="GameRating" id="GameRating-13164-3640" style="display: none;">
<span style="width: 68.14816px;"></span>
</span>
</a>
</div>
<div class="thumb" id="Thumb-13169-5946" style="position: absolute; left: 190px; top: 0px;">
<a href="/Spiderman-City-Raid">
<img src="/UploadFiles/2021-04-02/Spiderman-City-Raid.jpg">
<span class="GameName" id="GameName-13169-5946" style="display: none;">Spiderman - City Raid</span>
<span class="GameRating" id="GameRating-13169-5946" style="display: none;">
<span style="width: 67.01152px;"></span>
</span>
</a>
</div>
php处理:
复制代码 代码如下:
<"codetitle">复制代码 代码如下:
array (size=3)
'name' =>
array (size=2)
0 => string 'Spiderman City Drive' (length=20)
1 => string 'Spiderman - City Raid' (length=21)
'href' =>
array (size=2)
0 => string 'http://www.gahe.com/Spiderman-City-Drive' (length=40)
1 => string 'http://www.gahe.com/Spiderman-City-Raid' (length=39)
'img' =>
array (size=2)
0 => string 'http://www.gahe.com/thumb/12/Spiderman-City-Drive.jpg' (length=53)
1 => string 'http://www.gahe.com/thumb/12/Spiderman-City-Raid.jpg' (length=52)
强大的是pq选择器,语法类似jQuery,很方便。
phpQuery
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 群星2013-青春缤纷辑压箱宝大公开3CD2[新加坡限量版][WAV整轨]
- 林育群.2013-BalladShow(日本版)【环球】【WAV+CUE】
- 陈加洛.1992-痛到感觉不到【宝丽金】【WAV+CUE】
- 群星.2023-宿命之敌电视剧原声带【韶愔音乐】【FLAC分轨】
- 東京事変-大発見[FLAC+CUE]
- 椎名林檎-三文ゴシップ[FLAC+CUE]
- 2024年08月04日
- 裘德《裘德「最后的水族馆」演唱会LIVE》[320K/MP3][228.89MB]
- 裘德《裘德「最后的水族馆」演唱会LIVE》[24bit 48kHz][FLAC/分轨][2.08G]
- 基因三重奏《如果你什么都不说 音乐会现场录音》[320K/MP3][145.37MB]
- 孟庭苇.1996-月亮说话(2020环球24KGOLD限量版)【上华】【WAV+CUE】
- 群星.1997-新艺宝优质音响系列·国语精选监听版【新艺宝】【WAV+CUE】
- 阿桑.2005-寂寞在唱歌(星外星引进版)【华研国际】【WAV+CUE】
- 基因三重奏《如果你什么都不说 音乐会现场录音》[FLAC/分轨][287.43MB]
- 蔡题谦《我爱你,却依然要看你走》[320K/MP3][88.65MB]