Important string functions in PHP

Some functions are very common and we use them frequently in our projects. No matter which CMS or Framework we are using but as long as they are based on PHP we can utilize these PHP functions to perform some basic tasks.

implode() in PHP

The implode() function converts an array into an string and separate each element with the separator string provided as second parameter.

explode() in PHP

PHP explode() function breaks a string based on the delimiter and returns an array.


  1. Delimiter required
    This is the separater string
  2. String required
    This is the string which will be converted into array
  3. Limit optional
    If provided it will limit the elements of the array and last element will contain rest of the string.

Following code uses limit parameter as well.

lcfirst() in PHP

The lcfirst() function in PHP makes first character of the string lowercase.


string The string


string returned string with first character lowercased.

str_replace() in PHP

The str_replace() function replaces the searched string in a string. search string and replace string is passed as first and second argument while the third argument is string itself.

We can supply string or array as arguments for search and replace, let’s have a look how the function performs in both situtations.

strlen() in PHP

The Strlen() function returns the number of characters in a string. This function is useful in validations and mostly used in string manipulations in combination with other string functions of PHP.

strlen() function takes string as argument and return integer.
strlen() also counts spaces.

About Zohaib Shah

Passionate software engineer with expertise in Django, Laravel and NodeJS. Working with different SaaS based products and API connected apps. Software Architect of UK's leading online travel agency. Get in touch
View all posts by Zohaib Shah →

Leave a Reply

Your email address will not be published.