Home > Article > Backend Development > preg_replace_callback
<?phpfunction ac($m) { $acs = array ( 'www' => 'world wide web', 'irs' => 'internal revenue service', 'pdf' => 'portable document format'); //echo $m[0].",".$m[1]."<br/>"; if (isset($acs[$m[1]])) return $m[1]."(".$acs[$m[1]].")"; else return $acs[$m[1]];}$text = "wef <aaa>irs</aaa> rawfg <aaa>www</aaa> h <aaa>pdf</aaa> awf";$newtext = preg_replace_callback("/<aaa>(.*)<\/aaa>/U","ac",$text);print_r ($newtext);?>
$m[0]的值带标签<aaa>irs</aaa><aaa>www</aaa>
没懂你的意思
$m[0] 与 $m[1] 是不相等的
$m[0]的值带标签<aaa>irs</aaa><aaa>www</aaa>