Posted in PHP onJuly 10, 2017
本文实例讲述了PHP正则匹配操作。分享给大家供大家参考,具体如下:
<?php $str = <<< EOT <a href="www/app/a/2QRN7v" rel="external nofollow" > <div class="phonebg"> <img src="http://www/template9/yunqingjian/jianjie/68.jpg" > <div class="phoneclick"></div> <p>幸福领地</p> </div> </a> <a href="www/app/a/uqARNv" rel="external nofollow" > <div class="phonebg"> <img src="http://www/template9/yunqingjian/jianjie/69.jpg" > <div class="phoneclick"></div> <p>一世情长</p> </div> </a> EOT; if(preg_match_all('%<p.*?>(.*?)</p>%si', $str, $matches)) { $arr[0][] = $matches[1]; } if(preg_match_all('/src="([^<]*)" >/i', $str, $matches)) { $arr[1][] = $matches[1]; } print_r($arr); exit; ?>
运行结果如下:
Array ( [0] => Array ( [0] => Array ( [0] => 幸福领地 [1] => 一世情长 ) ) [1] => Array ( [0] => Array ( [0] => http://www/template9/yunqingjian/jianjie/68.jpg [1] => http://www/template9/yunqingjian/jianjie/69.jpg ) ) )
PHP正则匹配操作简单示例【preg_match_all应用】
- Author -
a771948524声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@