$str = <<<XXX
她们是<a target='_blank' href="http://www.xxx.com/index.php?from=2" onclick="">第一</a>名.
我们是<a href="http://www.xxx.com/index.php?var=2">第二</a>名.
你们是<a href="http://www.xxx.com/index.php?from=2">第三</a>名.
XXX;
$newstr=preg_replace("/(.*?)(from\=2)/ism","$1"."from=1001",$str);
print_r($newstr);