PHP 108105字节
在线尝试(108字节)
在线试用(105字节)
-3字节,感谢@manassehkatz(更改strtolower的级别并从正则表达式中删除AZ)
代码,试图避免任何循环
<?=strtr(implode(" ",str_split(preg_replace(
"/[^a-z]/",'',strtolower($argv)))),array_flip(range("`",z)));
说明
$string = preg_replace("/[^a-z]/",'',strtolower($argv))
//the string only contains letters
$string = implode(" ",str_split($string));
//the string has a space after every letter
$string = strtr($string, array_flip(range("`",z)));
//replace every letter acording to the array
$replacementArray = array_flip(range("`",z));
//this array contains the ansi characters from "`" to the "z"
//array_flip to change the keys with the values
//final array ["`"=>0,"a"=>1, "b"=>2...."z"=>26]