Reputation: 19
i want to make function to change letters to special letters like
i made this code
$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;
}
it should be ( н̈̈ǝ̈̈l̈̈l̈̈σ̈̈ м̈̈ӵ̈ ӥ̈ɑ̈̈м̈̈ǝ̈̈ ı̈̈ƨ̈̈ к̈̈ɑ̈̈я̈̈l̈̈ ) after i print.
the above code not working. so please help to me correct it.
regards
Upvotes: 1
Views: 131
Reputation: 1893
http://php.net/manual/en/function.str-replace.php
Look at this function.
$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 has functions for everything :P
Edit:
$search = array('h', 'a', 'm', 'e??', 'n', 'a', 'e?', 'i', 'z', 'k', 'a', 'r', 'l');
$replace = array('н̈̈','σ̈̈','м̈̈','ӵ̈','ӥ̈','ɑ̈̈','ǝ̈̈','ı̈̈','ƨ̈̈','к̈̈','ɑ̈̈','я'̈̈,'l̈̈');
$newString = str_replace($search, $replace, $string);
Upvotes: 3
Reputation: 75945
Using http://php.net/manual/en/function.str-replace.php and an array containing your characters you can easily do this
$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̈̈
Upvotes: 0
Reputation: 11440
$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);
http://php.net/manual/en/function.preg-replace.php
Upvotes: 0