split() is deprecated as of PHP 5.3.0

I am upgrading an old PHP website and I have found several deprecated functions one of them is “split()” which I used many times in the past. Which functions we can use right now? And why is this massive used function deprecated?

Instead of “split()” function you can use “explode()” if you are not using regular expressions in the same way that “split()”:

If you would need to use regular expressions you could use “preg_split()” function, as shown in the following example:

All of the examples have been taken from the official webpage, please visit the official website for further information:

Manual for preg_split() function

Manual for explode() function

Is brilliant to know that there is a great development behind PHP giving us upgrades and performance optimization, but why this function has been deprecated?

In the first case, using “explode()” we can found that it is substantially faster because it doesn’t split based on regular expression, so the string doesn’t have to be analyzed by the regex parser.

In the second case, using “preg_split()” has been deprecated in favor of the PCRE extension, which give us another question, is this the only function deprecated? And we found that “split()” function is member of a bunch of POSIX regex functions that they have also been deprecated and we can found them in the following document:

Differences from POSIX regex


Leave a Reply