$str = ':<a href="http://www.xxx.com/index.php?val=1"></a>
:<a href="http://www.xxx.com/index.php"></a>
:<a href="http://www.xxx.com/index.php?val=1"></a>';echo preg_replace( "/<a.+href=\"(.+)\".+>/Uise", "recover('\\1', 'news=1')", $str );function recover( $link, $added )
{
if( strpos( $link, "?" ) > 0 )
return $link . "&" . $added;
else
return $link . "?" . $added;
}

解决方案 »

  1.   

    上面写错了
    $str = ':asdfasdf<a href="http://www.xxx.com/index.php?val=1">sdf</a>asdfasdf
    :sadfasdf<a href="http://www.xxx.com/index.php">3r</a>sdfsaf
    :asdfasdf<a href="http://www.xxx.com/index.php?val=1">sdf</a>asdfasdf';echo preg_replace( "/(<a.+href=\")(.+)(\".+>)/Uise", "'\\1' . recover('\\2', 'news=1') . '\\3'", $str );function recover( $link, $added )
    {
    if( strpos( $link, "?" ) > 0 )
    return $link . "&" . $added;
    else
    return $link . "?" . $added;
    }
      

  2.   

    我的意思是这样的例如:
    其它网站通过一链接<a hrer="http://www.myweb.com/pin/index.php?from=7">亲密网</a>到达我的网站 http://www.myweb.com/pin/index.php ,这时我可以把from值取出来,放到我的index.php页面的所有链接中
      

  3.   

    估计用遍历网页上所有元素的方法可以实现,要用到 document.all 数组。
    具体实施我就不记得了,楼主可以用google查一下
      

  4.   

    $str = <<<XXX
    她们是<a target='_blank' href="http://www.xxx.com/index.php?val=1" onclick="">第一</a>名.
    我们是<a href="http://www.xxx.com/index.php?var=2">第二</a>名.
    你们是<a href="http://www.xxx.com/index.php?val=1">第三</a>名.
    XXX;$add=$_SERVER["QUERY_STRING"];$newstr=preg_replace("/(.*?)(\<a.*?href=[\"|'])(.*?)([\"|'].*?\>)/ism","$1$2"."$3"."&$add"."$4",$str);