$str = 'stRing';
ucfirst(strtolower($str));
Will output: String
Question
I've made a simple textbox which leads to a new page which echo's the input word by word (explode). Now i want to to change all the letters to lowercase except the first letter (if this is inputted this way)
for example : Herman Archer LIVEs in NeW YORK --> Herman Archer lives in new york
I hope you can help me out , thanks in advance!
No correct solution
OTHER TIPS
$str = 'stRing';
ucfirst(strtolower($str));
Will output: String
Just do
ucfirst(strtolower($string)); //Would output "Herman archer lives in new york"
Also if you wanted every word to start with a captial you could do
ucwords(strtolower($string)); //Would output "Herman Archer Lives In New York"
To make all chars of a string lowercase except the first, use:
echo $word[0] . strtolower(substr($word, 1));
Use mb_convert_case, but you have to create an equivalent to ucfirst:
<?php
function mb_ucfirst($string) {
$string = mb_strtoupper(mb_substr($string, 0, 1)) . mb_substr($string, 1);
return $string;
}
$string = 'hEllO wOrLD';
$string = mb_ucfirst(mb_convert_case($string, MB_CASE_LOWER));
echo $string; // Prints: Hello world
?>