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 av  a 2s  . 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 ww .  ja v  a  2  s.co  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  v a2  s.  c o  m*/

Result

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

Demo

<?php

$myString = "Hello, World!";
echo lcfirst( $myString ); // Displays'hello, World!'
?>/* ww w  .j av 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 w  w  .j a  va 2s . co  m*/

Result

Related Topic