使用php正则表达式提取html超链接中href地址信息
$str_href = "第三步:点右侧找个链接 <a href='http://www.qipa250.com' target='_blank' style='font-size: xx-large'>点击链接复制</a><input class=\"form-control\" type=\"text\" id=\"qipa250data\" placeholder=\"请将上面链接的结果粘贴到这里\" style=\"height:50px;\"><br> <button type=\"submit\" class=\"btn btn-success btn-lg btn-block\" id=\"qipa250parse\">奇葩天地网</button>";
//第一种
$preg_href = '/<a .*?href=\'(.*?)\'.*?>/is';
/*第二种
$preg_href = '/<a .*?href=\'(.*?)\'[\s\S]target/is';*/
preg_match_all($preg_href, $str_href, $res_href);
echo "<pre>";
var_dump($res_href[1][0]);
打印结果:
D:\wamp\www\hanshu\zhengze.php:26:string 'http://www.qipa250.com' (length=22)

本文介绍如何使用PHP正则表达式从HTML代码中提取超链接的href属性值,通过示例代码展示了两种匹配策略及其结果。
1万+

被折叠的 条评论
为什么被折叠?



