top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What Is The Difference Between Split And Explode Functions For String Manipulation In PHP?

0 votes
563 views
What Is The Difference Between Split And Explode Functions For String Manipulation In PHP?
posted Dec 26, 2017 by Jdk

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The split() and explode() are two main string function in php. The split() function splits the string into an array using a regular expression and returns an array. PHP split function takes three arguments, first parameter is pattern regular expression which is case sensitive, second is input string and thirst 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.

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

output:

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

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.

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

output:

array([0] => "is a string")
answer May 29, 2019 by Siddhi Patel
...