【发布时间】:2016-12-29 08:08:06
【问题描述】:
我在这里找到了答案:How to capitalize first letter of first word in a sentence? 但是,当句子以 " 或 « 等字符开头时,它不起作用。
在上面链接中找到的代码是:
$output = preg_replace('/([.!?])\s*(\w)/e', "strtoupper('\\1 \\2')", ucfirst(strtolower($input)));
这是我需要的处理示例
$input => «the first article title»
$output => «The first article title»
$input => « the first article title »
$output => « The first article title »
$input => "être"
$output => "Étre"
这个想法是忽略任何非字母(不在 [a-z, A-Z] + 法语字符中)并应用于第一个字母,其余的将与输入保持相同。
【问题讨论】:
-
$input的内容是什么?显示输入和预期输出 -
使用输入 => 输出示例更新问题。不可能从 cmets 中理解你想要的。
-
ucfirst()呢?
标签: php regex character-encoding