has a $link= "url", open after the code as follows: ...
- 2016-06-06 Yang Shan 2016 14 road greening project tender announcement
- 2016-06-06 Pingqiao District Minggang Town intersection-waste treatment yard-Hegang village South Junction (k0+000-k4+300) Road reconstruction project construction tender Notice
- 2016-05-31 Yang Shan branch of Xinyang City Center Hospital Public Defense Project Supervision tender notice
- 2016-05-31 Xinyang Hospital ward Building construction project construction and supervision Project tender announcement
!--Paging--> ...
目标:获得......中href标签里的内容"/news!show.action?id=2a7060f3519b40b3aa766dd53f2b00ad"我写的代码如下://获取链接中的内容$htmlContent=file_get_contents("$link");//获取链接$num=preg_match_all("/.*?(href=\".*?\").*/is",$htmlContent,$array);//打印数组var_dump($array[1]);目前卡顿的地方:在 //获取链接 处,子表达式只能获取一个结果,而且不是想要的href标签中的内容。
Reply content:
has a $link= "url", open after the code as follows: ...
- 2016-06-06 Yang Shan 2016 14 road greening project tender announcement
- 2016-06-06 Pingqiao District Minggang Town intersection-waste treatment yard-Hegang village South Junction (k0+000-k4+300) Road reconstruction project construction tender Notice
- 2016-05-31 Yang Shan branch of Xinyang City Center Hospital Public Defense Project Supervision tender notice
- 2016-05-31 Xinyang Hospital ward Building construction project construction and supervision Project tender announcement
!--Paging--> ...
目标:获得......中href标签里的内容"/news!show.action?id=2a7060f3519b40b3aa766dd53f2b00ad"我写的代码如下://获取链接中的内容$htmlContent=file_get_contents("$link");//获取链接$num=preg_match_all("/.*?(href=\".*?\").*/is",$htmlContent,$array);//打印数组var_dump($array[1]);目前卡顿的地方:在 //获取链接 处,子表达式只能获取一个结果,而且不是想要的href标签中的内容。
Look around should be able to meet your current needs.
preg_match_all('/(?<=\d{4}-\d{2}-\d{2}<\/span>)(?:.*?href=\")(.*?)(?:\".*?)(?=<\/li>)/is', $a, $matches);
array(2) { [0]=> array(4) { [0]=> string(152) " 羊山新区2016年14条道路绿化工程招标公告 " [1]=> string(218) " 平桥区明港镇井庄路口-垃圾处理场-何岗村南路口(K0+000-K4+300)公路改建工程施工招标公告 " [2]=> string(161) " 信阳市中心医院羊山分院人防工程监理招标公告 " [3]=> string(173) " 信阳市儿童医院病房楼建设项目施工及监理项目招标公告 " } [1]=> array(4) { [0]=> string(53) "/news!show.action?id=f435345c44e04ec3a5e6ccedca29e061" [1]=> string(53) "/news!show.action?id=ad4b065149d94704b3d295287f863b5a" [2]=> string(53) "/news!show.action?id=c3b688ae2ec54fb0880a0f60f7a4f5f0" [3]=> string(53) "/news!show.action?id=2a7060f3519b40b3aa766dd53f2b00ad" }}
Cause: Only one match result of course the subexpression has only one result.
If you change to:
$num = preg_match_all("/.*?(href=\".*?\").*?/is", $htmlContent, $array);
There are four match results for 4 matches.