phpquery能使得php操作html字符串像jquery一样简单,但是phpquery官方好像没有维护了,我们引入包使用querylist的依赖包,因为它是一直在单独github维护的
github地址:
https://github.com/jae-jae/phpQuery-single
(1).安装包
composer require jaeger/phpquery-single
(2).使用
$html = <<<STR
<div id="one">
<div class="two">
<a href="http://querylist.cc">QueryList官网</a>
<img src="http://querylist.cc/1.jpg" alt="这是图片">
<img src="http://querylist.cc/2.jpg" alt="这是图片2">
</div>
<span>其它的<b>一些</b>文本</span>
</div>
STR;
$doc = phpQuery::newDocumentHTML($html);
$src = $doc->find('.two img:eq(0)')->attr('src');
echo $src;
// http://querylist.cc/1.jpg尽量不要再去单独下载文件,或者可以从phpquery官网进行下载:
http://code.google.com/p/phpquery/
可能需要翻墙并单独引入
其他的操作方法可以百度phpquery 的实例进行使用
因为一个TP项目中客户需要全部网页分享支持自定义图片和描述信息,于是自己封装了下 //share()微信分享链接 //参数1 appid //参数2 appsert //参数3 nonceStr随机码 //参数4 timestamp时间戳 public&nb...
<!doctype html> <html> <head> <meta charset="utf-8"> <title>demo</title> </head> <bod...
//$ak开发密钥,$cityname城市名称(支持省县乡详细地址) public function getposition($ak,$cityname){ $callback=array('lng'=>0,'l...
项目需要使用websocket推送最新订单,客户服务器非linux不支持swoole,因此使用原生,直接上代码(1).PHP服务端<?php ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set...
参数中包含gb2312的字符串,返回结果是false或者null(不同PHP版本具有差异性)代码:<?php $dbms = 'mysql'; $host = '192.168.8.8'; $dbName =&n...
使用openssl扩展对应替换mcrypt的函数,(比较麻烦,但是openssl是未来趋势)在新版php中编译mcrypt扩展使用一个纯php代码实现的mcrypt扩展库,git地址为https://github.com/phpseclib/mcrypt_compat,每个mcrypt的方法都已经实...