39

What is the difference between explode and split in php?

David Refoua
  • 3,307
  • 1
  • 28
  • 51
Tejas Patel
  • 1,018
  • 3
  • 11
  • 17
  • possible duplicate of [What is the difference between split() and explode()?](http://stackoverflow.com/questions/3640990/what-is-the-difference-between-split-and-explode) – Narkha Aug 06 '15 at 07:46

4 Answers4

43

explode splits strings.

split (replaced with mb_split in newer versions of PHP) also does this, except it has support for splitting using regular expressions.

preg_split also does this and is 25-50% faster and has support for much more powerful Perl-compatible regular expressions.

amphetamachine
  • 25,180
  • 10
  • 57
  • 71
14

split uses regular expressions, while explode works with delimiter characters. Using split is discouraged, because it become deprecated in PHP 5.3.

tamasd
  • 5,526
  • 3
  • 26
  • 31
5

explode is generally faster than split ; but its not multibyte character safe.

We will use explode when we are absolutely guaranteed that our input is in single-byte character sets such as ISO-8859-1, and split when we are dealing with user input.

sushil bharwani
  • 28,837
  • 30
  • 92
  • 126
0

Both split and explode function splits the string into the array but split is used to split a string using regular expression while explode is used to split a string using another string.