What is the difference between split() and explode()?

split uses regex, while explode uses a fixed string. If you do need regex, use preg_split, which uses PCRE (the regex package now preferred across the PHP standard library).


Both the functions are used to Split a string.

However, Split is used to split a string using a regular expression.

On the other hand, Explode is used to split a string using another string.

E.g explode (" this", "this is a string"); will return “Is a string

E.g Split (" + ", "This+ is a string");


It's been deprecated because

  • explode() is substantially faster because it doesn't split based on a regular expression, so the string doesn't have to be analyzed by the regex parser
  • preg_split() is faster and uses PCRE regular expressions for regex splits

join() and implode() are aliases of each other and therefore don't have any differences.

Tags:

Php

Posix Ere