你能帮我制作一个时尚的文字生成器吗?

I want to make a text generator to give me texts with stylish letters like 鮩†ø and more instead of eRCTo. I found this:

/*
Code by ʍɨȼhą€ℓ
*/

$name = str_split('michael'); //Enter your name here
$letters = array("a"=>"ą", "b"=>"β", "c"=>"ȼ", "d"=>"ď", "e"=>"€", "f"=>"ƒ", "g"=>"ǥ", "h"=>"h", "i"=>"ɨ", "j"=>"j", "k"=>"Ќ", "l"=>"ℓ", "m"=>"ʍ", "n"=>"ɲ", "o"=>"๏", "p"=>"ρ", "q"=>"ǭ", "r"=>"я", "s"=>"$", "t"=>"ţ", "u"=>"µ", "v" => "ש","w"=>"ώ", "x"=>"ж", "y"=>"¥", "z"=>"ƶ");

$string = '';

$output = array(); 

foreach ($name as $key) { 
 if (array_key_exists($key, $letters)) { 
     $output[$key] = $letters[$key]; 

 } 
}

foreach ($output as $out) 
{
   $string .= "$out";
}  
echo $string;

It works with the name Michael great! But if I use aaabbcdd it returns ąβȼď. I want it to return duplicate letters too! What I should do?


Thanks For Every Helps. I changed the whole code. if anyone wanna the new and better code I'll put it to answers.


After some works on the last code I decided to write it from the first...it's even better than last one and can be customized easier.
You can improve it's code easily and feel free to use it

$name = str_split('aaabbcdd'); //Enter your name here


$letters = array("a"=>"ą", "b"=>"β", "c"=>"ȼ", "d"=>"ď", "e"=>"€", "f"=>"ƒ", "g"=>"ǥ", "h"=>"h", "i"=>"ɨ", "j"=>"j", "k"=>"Ќ", "l"=>"ℓ", "m"=>"ʍ", "n"=>"ɲ", "o"=>"๏", "p"=>"ρ", "q"=>"ǭ", "r"=>"я", "s"=>"$", "t"=>"ţ", "u"=>"µ", "v" => "ש","w"=>"ώ", "x"=>"ж", "y"=>"¥", "z"=>"ƶ");


$string = ''; 

foreach ($name as $key) { 
  if (array_key_exists($key, $letters)) {
    $string .= $letters[$key]; 
  }
}

echo $string;

I simplified it a bit. I removed the output array and appended the corresponding letters directly to the output string.

Now your script goes through the string char by char and appends the correct replacement directly to the output.

Output from michael: ʍɨȼhą€ℓ

Output from aaabbcdd: ąąąββȼďď

I think the problem was that you did overwrite the value, if the key was the same in the output array.

So with $output[$key] = $letter[$key] you set the key a but overwrote it with the next loop iteration if $key was a again.

With the script above this doesn't happen anymore.

Modify this :

foreach ($name as $key) { if (array_key_exists($key, $letters)) { $output[$key] = $letters[$key]; } }

into this :

foreach ($name as $key => $value) { if (array_key_exists($value, $letters)) { $output[$key] = $letters[$value]; } }

So the resulting array is not overwritten because of the same array key index.

Loop the string as an array and concat the result directly into output:

$name = 'michael'; //Enter your name here
$letters = array("a"=>"ą", "b"=>"β", "c"=>"ȼ", "d"=>"ď", "e"=>"€", "f"=>"ƒ", "g"=>"ǥ", "h"=>"h", "i"=>"ɨ", "j"=>"j", "k"=>"Ќ", "l"=>"ℓ", "m"=>"ʍ", "n"=>"ɲ", "o"=>"๏", "p"=>"ρ", "q"=>"ǭ", "r"=>"я", "s"=>"$", "t"=>"ţ", "u"=>"µ", "v" => "ש","w"=>"ώ", "x"=>"ж", "y"=>"¥", "z"=>"ƶ");

$output= '';
for($i=0;$i<strlen($name);$i++)
  if (array_key_exists($name[$i], $letters))
    $output .= $letters[$name[$i]]; 

echo $output;