将所有小写字母转换为对应的小型大写字母
Convert all lowercase letters to their corresponding smallcaps equivalents
当尝试将字符串中的所有字母从小写字母转换为小型大写字母 (Unicode characters representing capital letters at the height of lowercase letters) 时,是否有比 运行 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
结果
我正在查看是否有改进代码的方法。因为它看起来很乱,可能有更好的方法。
要在不使用非标准字符的情况下获得您正在寻找的结果,您可以使用 strtoupper()
函数并设置结果输出的样式:
<?php
$string = "Here is some text!";
$string = strtoupper( $string );
?>
<p><?= $string; ?></p>
p {
font-size: .8rem;
}
如果您真的需要那些奇怪的 unicode 字符,您至少可以通过使用一个 str_replace 和两个数组来搜索和替换字符来改进您的代码。
$my_str = str_replace(
array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",),
array("ᴀ","ʙ","ᴄ","ᴅ","ᴇ","ғ","ɢ","ʜ","ɪ","ᴊ","ᴋ","ʟ","ᴍ","ɴ","ᴏ","ᴘ","ᴏ","ʀ","s","ᴛ","ᴜ","ᴠ","ᴡ","x","ʏ","ᴢ",),
$my_str
);
当尝试将字符串中的所有字母从小写字母转换为小型大写字母 (Unicode characters representing capital letters at the height of lowercase letters) 时,是否有比 运行 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
结果
我正在查看是否有改进代码的方法。因为它看起来很乱,可能有更好的方法。
要在不使用非标准字符的情况下获得您正在寻找的结果,您可以使用 strtoupper()
函数并设置结果输出的样式:
<?php
$string = "Here is some text!";
$string = strtoupper( $string );
?>
<p><?= $string; ?></p>
p {
font-size: .8rem;
}
如果您真的需要那些奇怪的 unicode 字符,您至少可以通过使用一个 str_replace 和两个数组来搜索和替换字符来改进您的代码。
$my_str = str_replace(
array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",),
array("ᴀ","ʙ","ᴄ","ᴅ","ᴇ","ғ","ɢ","ʜ","ɪ","ᴊ","ᴋ","ʟ","ᴍ","ɴ","ᴏ","ᴘ","ᴏ","ʀ","s","ᴛ","ᴜ","ᴠ","ᴡ","x","ʏ","ᴢ",),
$my_str
);