Monday , September 25 2017
Home / PHP / PHP String functions Example Tutorials

PHP String functions Example Tutorials

In this tutorial we are going to discuss about PHP String and String functions.  Here String is one of the PHP data type.

PHP String :

PHP string is a collection of subsequent characters put together to form a sentence. There are many methods to manipulating a PHP string. Lets discuss one by one.,

PHP strlen()

The PHP strlen() function is used whenever the length of a string is required.


<?php
echo strlen("Hello My Name is Marry");
?>

Output :

22

Note that spaces are also counted as characters.

PHP str_word_count() :

PHP uses the str_word_count() function to output the number of words present in a string.


<?php
echo str_word_count("Hello My Name is Marry");
?>

Output :

5

PHP strrev() :

This function reverses a string. Written as strrev()


<?php
echo strrev("Hello");
?>

Output :

olleH

PHP strpos() :

PHP strpos() is a function used to search for text within a string. It returns the position of the first character or FALSE for 0 matches.


<?php
echo strpos("My Name is Chandra","Chandra");
?>

Output :

11

PHP str_replace() :

PHP str_replace() function is used to replace parts of a string. In the example below, the name Chandra will be replaced by Venu.


<?php
echo str_replace("Chandra","Venu","My Name is Chandra");
?>

Output :

My Name is Venu

Above are the mostly used string functions in PHP.

Keep Learning 🙂

About chandrashekhar

Hi Folks, you have reach this so far, that shows you like what you are learning. Then why don't you support us to improve for bettor tutorials by leaving your valuable comments and why not you keep in touch with us for latest updates on your favorite blog @ facebook , twitter , Or Google+ ,

Recommended

PHP File Handling fopen fread and fclose Example

PHP has the File handling functionalities that allows us to make dynamic operations on files. …

Leave a Reply

Your email address will not be published. Required fields are marked *