我在PHP中有一个字符串.我想用另一个字符的值交换某个字符.如果我这样做,A成为B将取代A与B,但已存在的B值将保持不变.当我尝试将B交换为A时,当然存在最初未交换的值,因为它们已经存在.
我试过这段代码.
$hex = "long_hex_string_not_included_here";
$hex = str_replace($a,$b,$hex);
//using this later will produced unwanted extra swaps
$hex = str_replace($b,$a,$hex);
Run Code Online (Sandbox Code Playgroud)
我正在寻找一个交换这些值的函数.