Commonly Used PHP functions for beginner

In this following article, we have some commonly used PHP functions which every beginner PHP developer must know and aware of it. Where it will help you at the time of interview as well as will enhance your coding skills.

These are few but important with a brief usage of each.


Gives all information about PHP version you are using.

error_reporting(0);   //Parameter can be 0 or 1

To show the PHP errors or hide


This function kills the entire script after its use.


Search a specific string into a given string


To count the total words into a string


To show the array in the proper format


To find the string length;

strtolower($string); & strtoupper($string);

To change the case of passed string

Strops(‘this is an example string’, ‘is’, $offset); //$offset can be a positive integer value which indicates to the function that from where we can start the search

Another function to search a specific part of the string from another string.

substr_replace($string, ‘$var’, 29, 4);

The above function will change the value of $string. It replaces the all characters from the node of 29 till next 4 positions with the $var value.

To change a part of string with another value is called “Word Censoring”

str_replace($find, $replace, $userinput);

Another function of word censoring. $find and $replace can be an array.

time() & date();

To show time and date


Will generate a random value between 1 to 6


Redirect to specified URL


Return true if empty.


To start the session.


Unset the session variable value. Mainly used while logging out.

setcookie(‘username’, ‘harish’, 5);

To set the Cookie. Last parameters are the time in second.

explode(‘,’, $data);

Create an array from a string. Create the value with the passed separator.

implode(‘ ’,$array_var);

create a string from a variable.


create a string into MD5 Hash code.

mail($to, $subject, $body, $headers);

E-mail function