Pau*_*xon 10
一种简单的方法是使用strtolower使字符串小写,而ucfirst大写第一个字符如下:
$str=ucfirst(strtolower($str));
Run Code Online (Sandbox Code Playgroud)
如果字符串包含多个句子,则必须编写自己的算法,例如在句子分隔符上爆炸并依次处理每个句子.除了第一个字符,您可能需要一些启发式方法来处理"I"之类的单词以及出现在文本中的任何常用专有名词.例如,像这样:
$sentences=explode('.', strtolower($str));
$str="";
$sep="";
foreach ($sentences as $sentence)
{
//upper case first char
$sentence=ucfirst(trim($sentence));
//now we do more heuristics, like turn i and i'm into I and I'm
$sentence=preg_replace('/i([\s\'])/', 'I$1', $sentence);
//append sentence to output
$str=$sep.$str;
$sep=". ";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3583 次 |
| 最近记录: |