Hello everyone, this article demonstrate some useful PHP functions which can be used to change string case into lowercase and uppercase. The article also demonstrate some other functions which can be used to convert first character of each word in a string or only the first character of string into lowercase and in uppercase.
1. strtoupper() : strtoupper() takes a string as parameter and convert each character of string into uppercase.
Syntax: strtoupper($string)
Example:
<?php
$string = "HellO woRld";
//---convert string into uppercase---
echo strtoupper($string);
?>
Output : HELLO WORLD
2. strtolower() : strtolower() takes string as parameter and convert all alphabetic characters of input string into lower case.
Syntax: strtolower($string)
Example : Input string same as above.
<?php
//---convert string into lowercase---
echo strtolower($string);
?>
Output : hello world
3. ucwords() : ucwords() convert first character into uppercase of each word in a string.
Syntax: ucwords($string)
Example :
<?php
$string = "this is another test string";
//---convert first character of each word into uppercase---
echo ucwords($string1);
?>
Output : This Is Another Test String
4. ucfirst() : ucfirst() convert first character of string into uppercase.
Syntax: ucfirst($string)
Example :
<?php
//---convert first character of string into uppercase---
echo ucfirst($string1);
?>
Output : This is another test string
5. lcfirst(): Just like ucfirst(), lcfirst() convert first character of input string into lowercase.
Syntax: lcfirst($string)
Example :
<?php
$string2 = "HELLO WORLD";
//---convert first character of string into lowercase---
echo lcfirst($string2);
?>
Output : hELLO WORLD
Note: All the above functions required a string as parameter.
0 Comment(s)