$search = [
'xyz', '123'
];
$replace = [
'123', '@@@'
];
//
$str = '#xyz123#';
//循环替换
$ret1 = str_replace($search, $replace, $str); //#@@@@@@#
//对位元素替换
$ret2 = strtr($str, ['xyz' => '123', '123' => '@@@']); //#123@@@#
//按 char 位替换,对应char位没有,则不处理
$ret3 = strtr($str, 'xyz123', '!'); //#!yz123# , 只替换了 a
深入理解:str_replace & strtr
最新推荐文章于 2022-11-13 20:53:21 发布