PHP String Function
String can be sequence of character or word , like - "Hello Word";
PHP string Function( )
We will discus following PHP String Function in this chapter
PHP strlen() Function
PHP strlen() function count number of character in string include space
Tips :It take one papameter
Example
<?php
$str = "Hello Word";
$countChar = strlen($str);
echo $countChar;
?>
Result
15 //There are 15 character space cover
PHP str_word_count() function
PHP word count function count number of word in a string
Tips : It take one parameter
Example
<?php
$str = "Hello Word";
$countWord = str_word_count($str);
echo $countWord;
?>
Result
2 // This number of word
PHP strrev() function
PHP strrev() function reverse the string
Tips :It take one parameter
Example
<?php
$str= "Hello Word";
$str_reverse = strrev($str);
echo $str_reverse;
?>
output
droW olleH
PHP strpos() function
PHP strpos() function find the position of text in the string
Tips : It take two parameter
Example
<?php
$str = "Hello Word";
$textPos = strpos($str , "Word"); //counting start from 0
echo $textPos;
?>
Result
6 //This position starting of word
PHP str_replace() function
PHP str_replace() function replace text from string