40

What is the difference between explode and split in php?

David Refoua
  • 3,476
  • 3
  • 31
  • 55
Tejas Patel
  • 1,078
  • 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

45

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
  • 27,620
  • 12
  • 60
  • 72
15

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

tamasd
  • 5,747
  • 3
  • 25
  • 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
  • 29,685
  • 30
  • 94
  • 128
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.