Php 字符串的正确大小写
我有上千个字符串,我想正确地将它们大写 默认字符串大小写可以更改 第二次世界大战->第二次世界大战 或 美国->美国Php 字符串的正确大小写,php,libraries,Php,Libraries,我有上千个字符串,我想正确地将它们大写 默认字符串大小写可以更改 第二次世界大战->第二次世界大战 或 美国->美国 有没有其他明智的资本化解决方案?我不知道为什么你的问题被否决了。无论如何,请查看下面的功能并根据您的要求进行调整 function titleCase($string) { $word_splitters = array(' ', '-', "O'", "L'", "D'", 'St.', 'Mc'); $lowercase_exceptions = array
有没有其他明智的资本化解决方案?我不知道为什么你的问题被否决了。无论如何,请查看下面的功能并根据您的要求进行调整
function titleCase($string)
{
$word_splitters = array(' ', '-', "O'", "L'", "D'", 'St.', 'Mc');
$lowercase_exceptions = array('the', 'van', 'den', 'von', 'und', 'der', 'de', 'da', 'of', 'and', "l'", "d'");
$uppercase_exceptions = array('III', 'IV', 'VI', 'VII', 'VIII', 'IX');
$string = strtolower($string);
foreach ($word_splitters as $delimiter)
{
$words = explode($delimiter, $string);
$newwords = array();
foreach ($words as $word)
{
if (in_array(strtoupper($word), $uppercase_exceptions))
$word = strtoupper($word);
else
if (!in_array($word, $lowercase_exceptions))
$word = ucfirst($word);
$newwords[] = $word;
}
if (in_array(strtolower($delimiter), $lowercase_exceptions))
$delimiter = strtolower($delimiter);
$string = join($delimiter, $newwords);
}
return $string;
}
最初提到@
希望这有帮助。干杯 我认为您可以使用php函数
希望这能有所帮助唯一的方法就是使用字典。。最好在谷歌上搜索一些现成的解决方案。你有没有尝试过自己制作一个智能字符串大小写,或者尝试过一个不同于内置的库?你的问题是关于Swift还是关于PHP?Marting R我想知道是客户端还是服务器端谢谢这很有帮助
string ucwords ( string $str [, string $delimiters = " \t\r\n\f\v" ] )