PHP string captialization

Php has 3 primary captialization function

  • strtoupper
  • strtolower
  • ucwords

Converting the String to upper case- strtoupper()

strtoupper () converts the string to upper case string

For eg:

<?php
echo "oldstring: ".$string="hello". "<br/>";
echo "newstring: ".$newstring=strtoupper($string);
?>

OUTPUT:
oldstring: hello
newstring: HELLO

Converting the String to lower case- strtolower()

strtolower() converts the string to lower case string

For eg:

<?php
echo "oldstring: ".$string="HELLO". "<br/>";
echo "newstring: ".$newstring=strtolower($string);
?>

OUTPUT:
oldstring: HELLO
newstring: hello

Converting the String to title case- ucwords()

ucwords() converts the string to title case string

For eg:

<?php
echo "oldstring: ".$string="welcome to my world". "<br/>";
echo "newstring: ".$newstring=ucwords($string);
?>

OUTPUT:
oldstring: welcome to my world
newstring: Welcome To My World

Posted in Php Tagged with: ,