en
Home About project

Convert case with PHP

If you need to convert a string to lower case or to upper case with PHP you can use next text functions:

  • strtoupper()
  • strtolower()
  • ucfirst()
  • ucwords()

strtoupper
- returns value of the called line converted to upper case.

Example of converting to upper case using strtoupper

$Str="hello, world!";
echo strtoupper($Str);

return the text "HELLO, WORLD!".


strtolower
- returns value of the called line converted to lower case.

Example of converting to lower case using strtolower

$Str="Hello, WORLD!";
echo strtolower($Str);

return the text "hello, world!".


ucfirst
- capitalize first letters of string.

Example of using ucfirst

$Str="hello, world!";
echo ucfirst($Str);

return the text "Hello, world!".


ucwords
- capitalize first letters of each word.

Example of using ucwords

$Str="hello, world!";
echo ucwords($Str);

return the text "Hello, World!".