小编Man*_*ama的帖子

如何用PHP交换字符串中两个不同字符的值?A变为B,B变为A.

我在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)

我正在寻找一个交换这些值的函数.

php string replace

0
推荐指数
1
解决办法
279
查看次数

标签 统计

php ×1

replace ×1

string ×1