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 的实例进行使用
参数中包含gb2312的字符串,返回结果是false或者null(不同PHP版本具有差异性)代码:<?php $dbms = 'mysql'; $host = '192.168.8.8'; $dbName =&n...
<?php /** * daemonize让当前脚本为守护进程执行 * @param string $callback 匿名函数 */ function daemonize($callback) {...
<?php $member = new class { public function getInfo() { ...
众所周知MyISAM引擎不支持事务,但是我只是知道不支持事务,并未测试具体的表现是什么,测试代码如下:try { //开启事务 Db::startTrans(); &...
//设置客户端断开依然运行 ignore_user_abort(true); //设置脚本不超时 set_time_limit(0); //死循环每隔1秒访问一次网址 while (true) { sleep(1); &nb...
sqlsrv扩展是php操作SQL Server的驱动下载地址:http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx下载完成后打开解压到指定目录,找到对应php版本的扩展,记得下载nts版本的。下载完扩展后,然后复制指定的dll文件到对应ph...