How does {code...} automatically match the corresponding content in $ a3 with $ a2? My mind was full of paste, so I couldn't think of it. I tried foreach for a long time and didn't get it out. I don't know that the passing PHP could provide a great solution ......
$a1 = '/\{[A-Z]*\}/';$a2 = array('{DOMEA} = 'AAAAAA';'{DOMEB} = 'BBBBBBB';)$a3 = return(' title {DOMEA} {DOMEB}');$b1 = preg_replace($a1,$a2,$a3);
How can we achieve $ a2 automatic matching of the corresponding content in $ a3?
My mind was full of paste, so I couldn't think of it. I tried foreach for a long time and didn't get it out. I don't know that the passing PHP could provide a great solution ......
Reply content:
$a1 = '/\{[A-Z]*\}/';$a2 = array('{DOMEA} = 'AAAAAA';'{DOMEB} = 'BBBBBBB';)$a3 = return(' title {DOMEA} {DOMEB}');$b1 = preg_replace($a1,$a2,$a3);
How can we achieve $ a2 automatic matching of the corresponding content in $ a3?
My mind was full of paste, so I couldn't think of it. I tried foreach for a long time and didn't get it out. I don't know that the passing PHP could provide a great solution ......
'AAAAAA','{DOMEB}'=>'BBBBBBB');$a3 = ' title {DOMEA} {DOMEB}';echo preg_replace_callback($a1, function($matches) use($a2) { return $a2[$matches[0]];}, $a3);?>
Http://3v4l.org/KudfG
This is not a regular expression, but it is the most commonstr_replaceNo ......
php$a2 = array('{DOMEA}' => 'AAAAAA','{DOMEB}' => 'BBBBBBB',);$a3 = 'title {DOMEA} {DOMEB}';echo str_replace(array_keys($a2), array_values($a2), $a3);
php
$a2 = array('{DOMEA}' => 'AAAAAA','{DOMEB}' => 'BBBBBBB',);$a3 = 'title {DOMEA} {DOMEB}';echo strtr($a3,$a2);