3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $url = '<div><a class="nk" href="http://weibo.cn/u/1610526293?st=968f">阳光下的雪海</a><span class="ctt">:<a href="http://weibo.cn/pages/100808topic?extparam=%E4%B8%AD%E5%9B%BD%E4%B9%8B%E5%A3%B0&amp;from=feed&amp;st=968f" class="k">#中国之声#</a> <a href="http://weibo.cn/sinaurl?f=w&amp;u=http%3A%2F%2Ft.cn%2FzO2NEZA&amp;st=968f">http://t.cn/zO2NEZA</a></span> &nbsp;<a href="http://weibo.cn/attitude/zAueIaySO/add?uid=1704540003&amp;rl=0&amp;st=968f">赞[0]</a>&nbsp;<a href="http://weibo.cn/repost/zAueIaySO?uid=1610526293&amp;rl=0&amp;st=968f">转发[0]</a>&nbsp;<a href="http://weibo.cn/comment/zAueIaySO?uid=1610526293&amp;rl=0&amp;st=968f#cmtfrm" class="cc">评论[0]</a>&nbsp;<a href="http://weibo.cn/fav/addFav/zAueIaySO?rl=0&amp;st=968f">收藏</a><!---->&nbsp;<span class="ct">1分钟前&nbsp;来自手机微博触屏版</span></div>'; preg_match_all("/(?<=href=\")[^\"]+(?=\")/", $url, $match); var_dump($match); echo preg_replace("/(?<=href=\")[^\"]+(?=\")/", "\\1\&afr=ad", $url);
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(1) { [0]=> array(7) { [0]=> string(36) "http://weibo.cn/u/1610526293?st=968f" [1]=> string(105) "http://weibo.cn/pages/100808topic?extparam=%E4%B8%AD%E5%9B%BD%E4%B9%8B%E5%A3%B0&amp;from=feed&amp;st=968f" [2]=> string(73) "http://weibo.cn/sinaurl?f=w&amp;u=http%3A%2F%2Ft.cn%2FzO2NEZA&amp;st=968f" [3]=> string(74) "http://weibo.cn/attitude/zAueIaySO/add?uid=1704540003&amp;rl=0&amp;st=968f" [4]=> string(68) "http://weibo.cn/repost/zAueIaySO?uid=1610526293&amp;rl=0&amp;st=968f" [5]=> string(76) "http://weibo.cn/comment/zAueIaySO?uid=1610526293&amp;rl=0&amp;st=968f#cmtfrm" [6]=> string(53) "http://weibo.cn/fav/addFav/zAueIaySO?rl=0&amp;st=968f" } } <div><a class="nk" href="\&afr=ad">阳光下的雪海</a><span class="ctt">:<a href="\&afr=ad" class="k">#中国之声#</a> <a href="\&afr=ad">http://t.cn/zO2NEZA</a></span> &nbsp;<a href="\&afr=ad">赞[0]</a>&nbsp;<a href="\&afr=ad">转发[0]</a>&nbsp;<a href="\&afr=ad" class="cc">评论[0]</a>&nbsp;<a href="\&afr=ad">收藏</a><!---->&nbsp;<span class="ct">1分钟前&nbsp;来自手机微博触屏版</span></div>