PHP string substitution problem, found how can not be achieved, please expert pointing
There is a requirement: there is a string ' abc ' that wants to replace the ' a ' in it with ' AB ', where ' B ' is replaced by ' CD ', that is, the last to get ' ABCDC '.
Find out how can not be achieved, such as with ' Str_replace '
$STR = ' abc ';
Var_dump (Str_replace ([' A ', ' B '], [' AB ', ' CD '], $STR));
The result returned is ' ACDCDC '. The ' str_replace ' process seems to be to replace ' a ' with ' ab ' to get ' abbc ', and then replace ' ABBC ' with ' B ' in ' CD ' to get ' ACDCDC ', the whole process is: ' abc ', ' Abbc ', ' ACDCDC '. ' Preg_replace ' is the same process.
Excuse me, how to realize ' abc ', ' ABCDC '???
Wait for the master, thank you very much
------to solve the idea----------------------
Do not hang in a tree, PHP has provided a variety of processing methods
$STR = ' abc ';
Echo strtr ($str, Array (' a ' = = ' ab ', ' b ' = ' CD '));
Abcdc