What is the difference between Split and Explode in PHP? ~ Interview Questions & Answers

Tuesday, February 10, 2009

What is the difference between Split and Explode in PHP?

The split() function splits the string into an array using a regular expression and returns an array.
Ex: split(":","India:Pakistan:Srilanka"); returns an array that contains India, Pakistan, Srilanka.
The explode() function splits the string by string.
Ex: explode("and", "India and Pakistan and Srilanka"); returns an array that contains India, Pakistan, Srilanka.
split() function is deprecated as of php5.3.0 . Use preg_split instead of split().

0 comments: