Ads

Difference Between Split And Explode In PHP

Encrypting your link and protect the link from viruses, malware, thief, etc! Made your link safe to visit.

 The split() and explode() are two main string function in php. If you are working in php, You may be use these php functions into your application. You have also faced some question in interviews regarding difference between php split and explode string function.

n this post, I will let you know what are the differences between Split() and Explode() php function with example.

Simple Usage And Example Of Split() PHP Function

The split() function is use to splits the string into an array using a regular expression.The split method returns an array of string data. PHP split() function takes three arguments, first parameter is pattern regular expression which is case sensitive, second is input string and third one is for limit: If the limit is set, the returned array will contain a maximum of limit elements with the last element containing the whole rest of string.

Warning
This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.Alternatives of split function in php7 –

How To Use PHP Split Function

split(":", "this:is:a:string"); //returns an array that contains this, is, a, string.

Output :


Array(
[0] => this,
[1] => is,
[2] => a,
[3] => string
)

Simple Usage And Example Of Explode() PHP Function

The php explode() function splits the string using delimiter and returns an array. PHP explode function takes three argument, first one takes delimiter as a argument, second one is target string and third one is limit : If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string.

Simple Example And Demo Of PHP Explode Function

The below example is used to explode the string using delimiter, The delimiter is this string. Passing first one argument as a delimiter and second one is source string.



explode ("this", "this is a string"); //returns an array that contains array "is a string"

Output


array([0] => "is a string")

0 Response to "Difference Between Split And Explode In PHP"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel