Posted on


A string is a collection of characters, like “Hello world!”.

 PHP String Functions

In this we will study about string and their functions.

 Get The Length of a String

The PHP strlen() function is use to get  length of a string.

Here we have a example to show the length of the string.


echo strlen(“php”); // outputs 3

Count The Number of Words in a String

The PHP str_word_count() function is use to counts the number of words in a string:

echo str_word_count(“my name arsh”); // outputs 3

 Reverse a String

The PHP strrev() function is use to reverses a string:


echo strrev(“Hello world!”); // outputs !dlrow olleH

Search Text from a String

The PHP strpos() function use for searches text from string.

If a match is found, the function returns the character position of the first match. If no match is found, it will return FALSE.

The example below searches for the text “world” in the string “Hello world!”:

echo strpos(“Hello world!”, “world”); // outputs 6

 Replace Text Within a String

The PHP str_replace() function replaces some characters with some other characters in a string.

In this example replaces the text “kool” with “Dolly”:

echo str_replace(“kool”, “Dolly”, “Hello kool!”); // outputs Hello Dolly!

For more details and queries please feel free to email, visit or call us. Wishing you the very best for all your future endeavors.

Helpline: 9814666333, 8699444666


Please fill the FORM and we shall contact you soon.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s