H-129, Palri, Hodal, Palwal, HR
+91 9992755268

PHP String Functions

PHP String Functions

PHP provides various string functions to access and manipulate strings. A list of important PHP string functions are given below

1. strlen() -Get The Length of a String

The strlen() function returns the length of the string.

<?php
echo strlen("LearnPHPonline.in"); // outputs 17
?>

2.strrev() – Reverse the String

The PHP strrev() function reverses a string:

<?php
echo strrev(“LearnPHPonline.in”); // outputs ni.enilnoPHPnrael
?>

3.strtolower() – convert string into lowercase

The strtolower() function returns string in lowercase letter.

<?php  
$str="LearnPHPonline.in";  
$str=strtolower($str);  
echo $str;   //output: learnphponline.in
?>

4. strtouper() – convert string into upercase

The strtouper() function returns string in lowercase letter.

<?php  
$str="LearnPHPonline.in";  
$str=strtouper($str);  
echo $str;   //output: LEARNPHPONLINE.IN
?>

5. ucfirst() – convert string into capitalize

The ucfirst() function returns string into capitalize letter( first letter uppercase)

<?php  
$str="learnphponline.in";  
$str=ucfirst($str);  
echo $str;   //output: Learnphponline.in
?>

6.str_replace()- replace a string

The PHP str_replace() function replaces some characters with some other characters in a string.

<?php
echo str_replace("LEARN", "Learn", "LEARN PHP online"); // outputs Learn PHP online!
?>

 

7.