PHP – Strings Functions

String functions are the most important functions frequently used in PHP. String is the sequence of characters, like “Let’s learn String functions”. There is no installation required to use string function.



$name = “Hirdesh Bhardwaj”;



String Concatenation Operator

To concatenate two string variables together, we use the dot (.) operator −


$txt1=”Hello Readers”;


echo $txt1 . ” ” . $txt2;


Using the strlen() function

The strlen() function is used to get the length of a string.


$txt=”Webs Jyoti”;

echo strlen($txt);


This will produce the following result – 10 (including space)

Using the strpos() function

The strpos() function is used to search for a text or character within a string. If the value is found then this will return the position of the first value. If no match is found, it will return FALSE.

Let’s see if we can find the string “PHP” in our string −


echo strpos(“Hello PHP”,”PHP”);


This will produce the following result – 6

The explode() Function: Used to convert strings into an array variable. It can be used in case where the information that you want lies in a larger string, you can extract it out with the explode() function.


$db = explode(‘;’,”host=localhost;db=hirdesh;uid=root “);



Array ( [0] => host=localhost [1] => db=hirdesh [2] => uid=root [3]

author image

About admin

You Might Also Like...

laravel training in gurgaon
php book written by indian author Hirdesh Bhardwaj
Hirdesh Bhardwaj

Enjoy the tutorial? Please spread the word :)

Follow by Email