$Array1=array( array('ID'=>'1','Name'=>'小王'), array('ID'=>'2','Name'=>'小李') );$strA='AA Name CC DD';$strB='/\s+(\w+)\s+/i';$Html=preg_replace($strB, $Array1[0][‘${2}’], $strA);echo $Html;
$Html=preg_replace($strB, ‘${2}’, $strA);
对于 php5.5 一下,可以
$Array1 = array( array('ID'=>'1','Name'=>'小王'), array('ID'=>'2','Name'=>'小李') ); $strA = 'AA Name CC DD';$strB = '/\s+(\w+)\s+/ie';$Html = preg_replace($strB, '$Array1[0]["$1"]', $strA);echo $Html;
$Array1 = array( array('ID'=>'1','Name'=>'小王'), array('ID'=>'2','Name'=>'小李') ); $strA = 'AA Name CC DD';$strB = '/\s+(\w+)\s+/i';$Html = preg_replace_callback($strB, function($m) use ($Array1) { return $Array1[0][$m[1]];}, $strA);echo $Html;
已抢16019个
抢已抢49013个
抢已抢4159个
抢已抢1782个
抢已抢2166个
抢已抢3570个
抢