Fonction ucfirst() | Développement Web

Fonction ucfirst()

La fonction ucfirst retourne la chaîne de caractère $string en passant la première lettre de cette chaîne en majuscule.

En combinant cette fonction avec la fonction strtolower, on peut alors récupérer une chaîne de caractères entièrement en minuscule et commençant cependant par une majuscule.

Utilisation de la fonction ucfirst()

La signature de la fonction ucfirst est la suivante :

ucfirst ( $string );


   $string = ' fonction ucfirst en php ';  

   echo ucfirst( $string );

   /* Affiche : Fonction ucfirst en php */   

   $string = ' foNCtion UCfirst en PHP ';  

   echo ucfirst( strtolower( $string ) );

   /* Affiche : Fonction ucfirst en php */