时间:2021-07-01 10:21:17 帮助过:2人阅读
<?php
$str = <<< EOT
<a href="www/app/a/2QRN7v" rel="external nofollow" >
<p class="phonebg">
<img src="http://www/template9/yunqingjian/jianjie/68.jpg" >
<p class="phoneclick"></p>
<p>幸福领地</p>
</p>
</a>
<a href="www/app/a/uqARNv" rel="external nofollow" >
<p class="phonebg">
<img src="http://www/template9/yunqingjian/jianjie/69.jpg" >
<p class="phoneclick"></p>
<p>一世情长</p>
</p>
</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正则匹配日期和时间(时间戳转换)的实例代码
PHP正则匹配所有字符失败的原因及解决办法
PHP简单实现正则匹配省市区的方法
以上就是PHP实现正则匹配操作的方法的详细内容,更多请关注Gxl网其它相关文章!