如何在PHP中将句子中的第一个字母大写?
可能的重复:
如何将第一个字母显示为大写?
PHP 将句子中第一个单词的第一个字母大写
我想将句子中的第一个字母和句号后的字母大写。谁能建议怎么做?
例如,
//I have the following in a language class.
"%s needs to identify areas of strength and
weakness. %s sets goals for self-improvement.";
// in a view
$contone=$this->lang->line($colstr);// e.g get the above string.
//$conttwo=substr($contone, 3);//skip "%s " but this doesnot work when there
//are more than one %s
$conttwo=str_replace("%s ", "", $contone);// replace %s to none
$contthree = ucfirst($conttwo); // this only uppercase the first one
我想要以下输出。
Needs to identify areas of strength and
weakness. Sets goals for self-improvement.
Possible Duplicate:
How do I display the first letter as uppercase?
PHP capitalize first letter of first word in a sentence
I want to uppercase the first letter in a sentence and after a period. Can anyone suggest how to do?
For example,
//I have the following in a language class.
"%s needs to identify areas of strength and
weakness. %s sets goals for self-improvement.";
// in a view
$contone=$this->lang->line($colstr);// e.g get the above string.
//$conttwo=substr($contone, 3);//skip "%s " but this doesnot work when there
//are more than one %s
$conttwo=str_replace("%s ", "", $contone);// replace %s to none
$contthree = ucfirst($conttwo); // this only uppercase the first one
I want the following output.
Needs to identify areas of strength and
weakness. Sets goals for self-improvement.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试下面。
它将运行该函数,将具有多个句子的字符串中句号(句点)后的每个字母大写。
请进行必要的更改。
Try below.
It will run the function to capitalize every letter AFTER a full-stop (period) in a string having multiple sentences.
Please do required changes.
试试这个:
Try this: