6

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!

Syff
  • 79
  • 1
  • 1
  • 2

4 Answers4

19
$str = 'stRing';
ucfirst(strtolower($str));

Will output: String

James Elliott
  • 1,012
  • 9
  • 20
8

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"
Pattle
  • 5,983
  • 8
  • 33
  • 56
2

To make all chars of a string lowercase except the first, use:

echo $word[0] . strtolower(substr($word, 1));
Robin Webdev
  • 479
  • 2
  • 7
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

?>
Zanshin13
  • 980
  • 4
  • 19
  • 39
Arno
  • 23
  • 5