日期:2014-05-17 浏览次数:20467 次
if(preg_match("/id=[\d]+$/",$url,$result)) { echo $result[1]; }
------解决方案--------------------
$s=<<<txt <a target="_blank" href="http://detail.tmall.com/item.htm?id=4476817718"></a> </div> ...... <div class="desc"> <a target="_blank" href="http://detail.tmall.com/item.htm?id=4285064738" class="permalink" style="">描述</a></div> txt; echo preg_replace('/href=".+?id=(\d+)"/is',"href=\"javascrpit:clickItem('$1')\"",$s);
------解决方案--------------------
<?php
$s = <<<TEXT
<a target="_blank" href="http://hello.tmall.com/good.html?id=99888889">a</a>
<a target="_blank" href="http://hello.tmall.com/item.html?id=99888889">b</a>
<a target="_blank" href="http://hello.tmall.com/okitd.html?uid=099889999$id=99888889">c</a>
<a target="_blank" href="http://hello.tmall.com/item.html?cid=099889999">d</a>
<a target="_blank" href="http://detail.tmall.com/item.htm?spm=a2106.m874.1000384.d11&id=15393357623&pm2=1&source=dou&scm=1029.0.1.0">e</a>
<a target="_blank" href="http://item.taobao.com/item.htm?id=9999999999999">f</a>
TEXT;
echo preg_replace('/href=".+?item\\.html?.*?[^\\w]id=([0-9]+)(.*)"/i','href="javascrpit:clickItem(\'$1\')"',$s);
?>