时间:2021-07-01 10:21:17 帮助过:4人阅读
$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);
$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;