Uppercase first letter and rest lower

别等时光非礼了梦想. 提交于 2019-12-02 13:14:48
function totitle($string){
  return ucfirst(strtolower($string));
}

And voila :)

You should go like this

<?php
$string= 'HELLO WORLD';
$string = strtolower($string);
$string = ucfirst($string);
?>

"Title" casing capitalizes each word in a string (i.e. every letter following white space). Your approach would result in "Gone with the wind," whereas title casing would yield "Gone With The Wind".

I wouldn't worry about it: what you're doing is simple and intuitive, and if it gets you what you want, there's not any intrinsic functions that do the same thing.

George Sovetov

You can create such function yourself.

Do not forget that you should use mb_* functions for data that was input by user. English is not the only language people use. Look at this question: ucfirst() function for multibyte character encodings

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!