gpt4 book ai didi

PHP替换单词中的每个字母

转载 作者:行者123 更新时间:2023-12-03 23:01:49 24 4
gpt4 key购买 nike

我需要一个函数来用其他字母替换单词中的每个字母。例如:

a = tu
b = mo
c = jo

如果我写“abc”,我想得到“tumoji”,如果我写“bca”,我想得到“mojotu”,等等

最佳答案

$from = array('a',
'b',
'c'
);
$to = array('tu',
'mo',
'jo'
);
$original = 'cab';
$new = strtr($original,$from,$to);

$replacements = array('a' => 'tu',
'b' => 'mo',
'c' => 'jo'
);
$original = 'cab';
$new = strtr($original,$replacements);

$replacements = array('a' => 'tu',
'b' => 'mo',
'c' => 'jo'
);
$original = 'cab';
$new = '';
foreach(str_split($original) as $letter) {
$new .= $replacements[$letter];
}

关于PHP替换单词中的每个字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8693260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com