31

I have the following statement which worked fine before PHP 5.3 using the split function:

$command = split (" ", $tag[1]);

After upgrading to PHP 5.3, I get the Deprecated warning:

Deprecated: Function split() is deprecated.
Chris45234325
  • 407
  • 1
  • 4
  • 7
  • Have you look at the documentation on [`split()`](http://php.net/split)? In this case you need [`explode()`](http://php.net/explode). – Ja͢ck Jul 23 '13 at 16:32

3 Answers3

54

Use explode:

$command = explode(" ", $tag[1]);

This is the standard solution for this case.

If you need to match on a regular expression (rather than something simple like a space), use preg_split. It's slower than explode, so there's no reason to use it unless you need a regex.

BTW to do the opposite (join array elements into a string), use implode.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
user428517
  • 4,132
  • 1
  • 22
  • 39
3

From this page:

Tip

split() is deprecated as of PHP 5.3.0. preg_split() is the suggested alternative to this function. If you don't require the power of regular expressions, it is faster to use explode(), which doesn't incur the overhead of the regular expression engine.

If you are going to split in " " you might consider explode to be a better alternative.

Hristo Valkanov
  • 1,689
  • 22
  • 33
3

Well the first thing someone should do is checking the documenation: split

It is recommended to use preg_split or explode

Tobias Golbs
  • 4,586
  • 3
  • 28
  • 49