批量修改,规则:
<a href="javascript:void(0)" onclick="js('name1','x')" title="name2">name2</a>
变成
<a href="http://localhost/search.php?word=name2&start='.$num.'" target="_blank" title="name2">name2</a>说明: $num是一个外部变量。word=name2 里的 name2 是hyperlink里的title值。下面的代码不起作用,哪里的问题?谢谢。
<?php
$num= '11';//随便赋了个值,做测试。
$str = <<<ETO
<a href="javascript:void(0)" onclick="js('name1','x')" title="name2">name2</a>
ETO;
echo preg_replace('%href="javascript:void(0)" onclick="(.*?)" title="(.*?)"%is', 'href="http://localhost/search.php?word=$2&start='.$num.'" target="_blank"', $str);
?>