String Functions in PHP
String Functions in PHP
PHP have lots of predefined function which is used to perform operation with string some functions are strlen(), strrev(), strpos() etc.

PHP strlen() function
strlen() function returns the length of a string. In below example strlen() function is used to return length of "Hello world!"
strlen() example in php
<?php echo strlen("Hello world!"); ?>
Output
PHP str_word_count() function
str_word_count() function is used to count numbers of words in given string.
str_word_count() example in php
<?php echo str_word_count("Hello world!"); ?>
Output
PHP strrev() function
strrev() function is used to revers any string.
strrev() example in php
<?php echo strrev("Hello world!"); ?>
Output
PHP strpos() function
strpos() function is used to search specific position of any words in given string.
strpos() example in php
<?php echo strpos("Hello world!", "world"); ?>
Output
PHP str_replace() function
str_replace function is used to replaces some characters with some other characters in a string. In below example we replace world with Faiz.
str_replace() example in php
<?php echo str_replace("world", "Faiz", "Hello world!"); ?>
PHP strtolower() function
strtolower() function is used to convert uppercase latter into lowercase latter.
strtolower() example in php
<?php $str="Hello friends i am HITESH"; $str=strtolower($str); echo $str; ?>
Output
PHP strtoupper() function
PHP strtoupper() function is used to convert lowercase latter into uppercase latter.
strtoupper() example in php
<?php $str="Hello friends i AM Hitesh"; $str=strtoupper($str); echo $str; ?>
Output
Output
PHP ucwords() function
ucwords() function is used to convert first latter of every word into upper case.
ucwords() example in php
<?php $str="hello friends i am hitesh"; $str=ucwords($str); echo $str; ?>
Output
PHP ucfirst() function
ucfirst() function returns string converting first character into uppercase. It doesn't change the case of other characters.
ucfirst() example in php
<?php Hello friends I am HITESH ?>
Output
PHP lcfirst() function
PHP lcfirst() function is used to convert first character into lowercase. It doesn't change the case of other characters.
lcfirst() example in php
<?php hello friends I am HITESH ?>