我想将函数更改为特殊字母,如
我制作了这段代码
$text = "hello my name is karl";
$my_array = array('н̈̈','σ̈̈','м̈̈','ӵ̈','ӥ̈','ɑ̈̈','ǝ̈̈','ı̈̈','ƨ̈̈','к̈̈','ɑ̈̈','я','l̈̈');
for ($i = 0, $len = strlen($text); $i < $len; $i++) {
$random = @array_rand($text[$i]); # one random array element number
$get_it = $my_array[$random]; # get the letter from the array
echo $get_it;
}
打印后,它应该是(̈̈ǝ̈̈̈̈ǝ̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈̈ǝ̈̈̈̈ǝ̈̈̈̈ǝ̈̈̈̈ǝ̈̈̈̈ǝ̈̈̈̈ǝ̈̈̈̈ǝ̈̈̈̈ƨ̈̈̈̈ƨ̈̈̈̈ƨ̈̈̈̈ƨ̈̈̈̈̈̈)。
以上代码无效。所以请帮助我纠正它。
问候
答案 0 :(得分:3)
http://php.net/manual/en/function.str-replace.php
看看这个功能。
$s = array('e', 'something else to search for');
$r = array('é', 'something to replace "something else to search for" with');
$stringy = str_replace($s, $r, $string);
PHP具有一切功能:P
编辑:
$search = array('h', 'a', 'm', 'e??', 'n', 'a', 'e?', 'i', 'z', 'k', 'a', 'r', 'l');
$replace = array('н̈̈','σ̈̈','м̈̈','ӵ̈','ӥ̈','ɑ̈̈','ǝ̈̈','ı̈̈','ƨ̈̈','к̈̈','ɑ̈̈','я'̈̈,'l̈̈');
$newString = str_replace($search, $replace, $string);
答案 1 :(得分:0)
$string = 'The quick brown fox jumped over the lazy dog.';
$patterns = array();
$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';
$replacements = array();
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $string);
答案 2 :(得分:0)
使用http://php.net/manual/en/function.str-replace.php和包含角色的数组,您可以轻松完成此操作
$yourtext = "hello my name is karl"; //Place your text in this
//Match your characters that you'de like to replace
$after = array('н̈̈','σ̈̈','м̈̈','ӵ̈','ӥ̈','ɑ̈̈','ǝ̈̈','ı̈̈','ƨ̈̈','к̈̈','я','l̈̈');
$before = array('h','o','m','y','n','a','e','i','s','k','r','l');
$yourtext = str_replace ( $before , $after , $yourtext, $replacing);
echo $yourtext; //prints н̈̈ǝ̈̈l̈̈l̈̈σ̈̈ м̈̈ӵ̈ ӥ̈ɑ̈̈м̈̈ǝ̈̈ ı̈̈ƨ̈̈ к̈̈ɑ̈̈я̈̈l̈̈