PHP正則マッチングaリンク
1268 ワード
$html='<div class="prop_1 clearfixs">';
$html.="
";
$html.='<span class="prop_s">
<a class="a1">21 </a> <a href="http://125life.com/index.php?r=lfb%2Fdh%2Fsearch&catid=0&page=0" class="a1"> </a> <span>1</span> <a href="http://125life.com/index.php?r=lfb%2Fdh%2Fsearch&catid=0&page=2">2</a> <a href="http://125life.com/index.php?r=lfb%2Fdh%2Fsearch&catid=0&page=2" class="a1"> </a></span>
</div>';
echo preg_replace('/(<a[\S\s]*?href=")[^"]*?page=(\d)("[\S\s]*?>)/','$1javascript:LFB.SearchSetPage($2);$3',$html);
結果は次のとおりです.
<div class="prop_1 clearfixs">
<span class="prop_s">
<a class="a1">21 </a> <a href="javascript:LFB.SearchSetPage(0);" class="a1"> </a> <span>1</span> <a href="javascript:LFB.SearchSetPage(2);">2</a> <a href="javascript:LFB.SearchSetPage(2);" class="a1"> </a></span>
</div>