[ACCEPTED]-Function split() is deprecated" in PHP?-split

Accepted answer
Score: 36

http://php.net/manual/en/function.split.php

From the manual

Warning This function has 9 been DEPRECATED as of PHP 5.3.0. Relying 8 on this feature is highly discouraged

Note:

As 7 of PHP 5.3.0, the regex extension is deprecated 6 in favor of the PCRE extension. Calling 5 this function will issue an E_DEPRECATED 4 notice. See the list of differences for 3 help on converting to PCRE.

I guess you're 2 supposed to use the alternative preg_split(). Or if 1 you're not using a regex, just use explode

Score: 9

split has been replaced with explode, see http://php.net/explode for 5 more information. Works the same as split, but 4 split is 'deprecated' basically means that 3 is a old function that shouldn't be used 2 anymore, and is not likely to be in later 1 versions of php.

Score: 5

Use following explode function:

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

This is the 2 standard solution for this case. Its Perfectly 1 working.

Score: 3

Ahh, the docs says about it. And the docs also 2 say which functions should be used instead 1 of this:

  1. preg_split
  2. explode
  3. str_split
Score: 1

Because the function has been deprecated? You 5 can customize the error_reporting level 4 to not log / display the depreciated errors. But 3 it would be more prudent to just correct 2 the issue (IE use explode instead for the 1 simple split you are doing above.)

Score: 0

You can use this custom function for old 1 codes:

if (!function_exists('split')) {
    function split($pattern, $subject, $limit=-1, $flags=0){
        return preg_split($pattern, $subject, $limit, $flags);
    }
}

More Related questions