最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php正则匹配a标签的例子
时间:2022-06-25 02:41:34 编辑:袖梨 来源:一聚教程网
方法一
代码如下 | 复制代码 |
$a ='百度谷哥谷歌雅虎'; 得出结果 Array ( [0] => Array ( [0] => 百度 [1] => 谷歌 [2] => 雅虎 )
) |
方法二
示例如下:
代码如下 | 复制代码 |
$str1 = 'test'; $str2 = 'test'; $str3 = 'test'; $regex = '/hrefs*=s*(?:"([^"]*)"|'([^']*)'|([^"'>s]+))/'; preg_match($regex, $str1, $matches); print_r($matches); preg_match($regex, $str2, $matches); print_r($matches); preg_match($regex, $str3, $matches); print_r($matches); 匹配结果: Array ( [0] => href=http://www.111com.net [1] => [2] => [3] => http://www.111com.net ) Array ( [0] => href='http://www.111com.net' [1] => [2] => http://www.111com.net ) Array ( [0] => href = "javasccript: href ('test');" [1] => javasccript: href ('test'); ) |
/hrefs*=s*(?:"([^"]*)"|'([^']*)'|([^"'>s]+))/
思路很巧妙,即:
分两步,先区配a标签,然后再区配a标签里面的链接
相关文章
- 第五人格佣兵护腕怎么用 第五人格佣兵护腕教学 04-28
- 崩铁星穹列车年度开拓报告活动怎么玩 星穹列车年度开拓报告网页活动介绍 04-28
- 逆水寒手游五子棋残局三十二怎么过 04-28
- 崩坏星穹铁道齐颂给谁用 04-28
- 火影忍者手游旋涡鸣人仙人模式怎么玩 04-28
- 原神怎么破坏磐键 原神破坏磐键的方法 04-28