What is the difference between explode
and split
in php?

- 3,476
- 3
- 31
- 55

- 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 Answers
explode
splits strings.
(replaced with split
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.

- 27,620
- 12
- 60
- 72
split
uses regular expressions, while explode
works with delimiter characters. Using split
is discouraged, because it become deprecated in PHP 5.3.

- 5,747
- 3
- 25
- 31
-
1sir it may,in php 5.3 split use with preg_split().? may i right sir? – Tejas Patel Sep 11 '10 at 09:53
-
3yes, you should use preg_split() if you want to split the string with regular expressions – tamasd Sep 11 '10 at 10:42
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.

- 29,685
- 30
- 94
- 128
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.

- 73
- 7