当尝试将字符串中的所有字母从小写字母转换为小型大写字母(Unicode 字符代表小写字母高度处的大写字母)时,是否有比为字母表中的每个字母运行一次 str_replace 更简单的方法?
我的字符串
$my_str = 'there has to be an easier way than this mess';
漫长的过程
//Replace Values from my_str
$my_str = str_replace("a", "ᴀ", $my_str);
$my_str = str_replace("b", "ʙ", $my_str);
$my_str = str_replace("c", "ᴄ", $my_str);
$my_str = str_replace("d", "ᴅ", $my_str);
$my_str = str_replace("e", "ᴇ", $my_str);
$my_str = str_replace("f", "ғ", $my_str);
$my_str = str_replace("g", "ɢ", $my_str);
$my_str = str_replace("h", "ʜ", $my_str);
$my_str = str_replace("i", "ɪ", $my_str);
$my_str = str_replace("j", "ᴊ", $my_str);
$my_str = str_replace("k", "ᴋ", $my_str);
$my_str = str_replace("l", "ʟ", $my_str);
$my_str = str_replace("m", "ᴍ", $my_str);
$my_str = str_replace("n", "ɴ", $my_str);
$my_str = str_replace("o", "ᴏ", $my_str);
$my_str = str_replace("p", "ᴘ", $my_str);
$my_str = str_replace("q", "ᴏ", $my_str);
$my_str = str_replace("r", "ʀ", $my_str);
$my_str = str_replace("s", "s", $my_str);
$my_str = str_replace("t", "ᴛ", $my_str);
$my_str = str_replace("u", "ᴜ", $my_str);
$my_str = str_replace("v", "ᴠ", $my_str);
$my_str = str_replace("w", "ᴡ", $my_str);
$my_str = str_replace("x", "x", $my_str);
$my_str = str_replace("y", "ʏ", $my_str);
$my_str = str_replace("z", "ᴢ", $my_str);
然后显示
// Display replaced string
echo $my_str
输出(它有效但看起来很乱且编码不佳)
ᴛʜᴇʀᴇ ʜᴀs ᴛᴏ ʙᴇ ᴀɴ ᴇᴀsɪᴇʀ ᴡᴀʏ ᴛʜᴀɴ ᴛʜɪs ᴍᴇss
结果
我正在查看是否有改进代码的方法。因为它看起来很乱,可能有更好的方法来做到这一点。
拉莫斯之舞
人到中年有点甜