PHP - String Uppercase and Lowercase

Introduction

To convert a string to all lowercase, use strtolower().

This function takes a string, and returns a converted copy of the string:

Demo

<?php

$myString = "Hello, world!";
echo strtolower( $myString ); // Displays'hello, world!'
?>/*from w w  w .  j a v  a 2  s . co m*/

Result

You can use strtoupper() to convert a string to all uppercase:

Demo

<?php

$myString = "Hello, world!";
echo strtoupper( $myString ); // Displays'HELLO, WORLD!'
?>/*from  w w  w. j a  v  a2 s  .c  o  m*/

ucfirst()  makes just the first letter of a string uppercase:

Result

Demo

<?php

$myString = "hello, world!";
echo ucfirst( $myString ); // Displays'Hello, world!'
?>/*from w  w w  . ja va 2s .com*/

Result

lcfirst() makes the first letter of a string lowercase:

Demo

<?php

$myString = "Hello, World!";
echo lcfirst( $myString ); // Displays'hello, World!'
?>/*  w  w  w . j  a  v a 2  s  . c o m*/

Result

Finally, ucwords() makes the first letter of each word in a string uppercase:

Demo

<?php

$myString = "hello, world!";
echo ucwords( $myString ); // Displays'Hello, World!'
?>/*w  ww  .  ja va 2s  . c  o m*/

Result

Related Topic