Monday , January 22 2018
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.

echo strlen("Hello My Name is Marry");

Output :


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.

echo str_word_count("Hello My Name is Marry");

Output :


PHP strrev() :

This function reverses a string. Written as strrev()

echo strrev("Hello");

Output :


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.

echo strpos("My Name is Chandra","Chandra");

Output :


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.

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

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+ ,


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 *