【发布时间】:2019-06-02 01:07:21
【问题描述】:
我在 PHP 中有一个字符串。我想用另一个字符的值交换某个字符。如果我按照自己的方式做,A 变成 B 将用 B 替换 A,但已经存在的 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);
我正在寻找一个函数来交换这些值。
【问题讨论】: