blog

Home / DeveloperSection / Blogs / PHP String Function

PHP String Function

zack mathews 1502 07-Jun-2016

 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



php php  string 
Updated 15-Mar-2018

Leave Comment

Comments

Liked By