Home > DeveloperSection > Blogs > PHP String Function

PHP String Function


PHP PHP  String 
Ratings:
0 Comment(s)
 136  View(s)
Rate this:

PHP String Function


 Here we will look on some of the function of strings:


strlen() :To get the length of the string.example:

<?php

$t="hello";

echo strlen($t);

?>

 

Result:

5


str_word_count : count the number of words

<?php

echo str_word_count("Hello world!"); 

?>

 

Result:

2


strrev(): It is used to reverse the string

<?php

echo strrev("Good Morning!"); 

?>

 

Output:

!gninroM dooG


strpos() : Search for specific text with in a string:

<?php

echo strpos("Hello world!", "r");

?>

 

Output:

8


str_replace:Replace one character from other character.

<?php

echo str_replace("Morning" , "afternoon","Good Morning");

?>

 

Output:

Good afternoon



Don't want to miss updates? Please click the below button!

Follow MindStick