Search code examples
phpposix-ere

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


The PHP manual for split() says

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged...Use explode() instead.

But I can't find a difference between split() and explode(). join() hasn't been deprecated, so what gives?


Solution

  • 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.