Monday, 20 July 2015

PHP Functions for Words Formatting

PHP functions are used for text formatting. Formatting like uppercase, lowercase and first letter uppercase can also be done using php functions, here is the 5 php functions for words/text formatting
  • ucwords
  • strtoupper
  • strtolower
  • ucfirst
  • lcfirst
ucwords()
Make each word’s first letter as capital letter
1
2
3
4
$text = "freeze coders";

$text1 = ucwords($text)// Output -  Freeze Coders

strtoupper()
strtoupper php function will make all words as upper case(capital letter)
1
2
3
4
$text = "freeze coders";

$text1 = strtoupper($text)// Output -  FREEZE CODERS

strtolower()
strtolower php function will make all words as lower case(capital letter)
1
2
3
4
$text = " FREEZE CODERS";

$text1 = strtolower($text)// Output -  freeze coders

ucfirst()
ucfirst php function will make the first letter of a string as uppercase
1
2
3
4
$text = "freeze coders";

$text1 = ucfirst($text)// Output -  Freeze coders

lcfirst()
lcfirst() php function will return the string’s first letter lowercase
1
2
3
4
$text = " FREEZE CODERS";

$text1 = lcfirst($text)// Output -  fREEZE CODERS

0 comments:

Post a Comment