public function split($string, $separator = null, $limit = null)
    {
        $string = (string)$string;

        if ($separator === null) {
            return [$string];
        }
        if ($separator === '') {
            $result = str_split($string);
            if ($limit !== null) {
                $result = array_slice($result, 0, $limit);
            }
            return $result;
        }
        if ($limit === null) {
            $result = explode($separator, $string);
        } else {
            $result = explode($separator, $string, $limit);
        }
        return $result;
    }
public function split($string, $separator = null, $limit = null)
    {
        $string = (string)$string;

        if ($separator === null) {
            return [$string];
        }
        if ($separator === '') {
            $result = str_split($string);
            if ($limit !== null) {
                $result = array_slice($result, 0, $limit);
            }
            return $result;
        }
        if ($limit === null) {
            $result = explode($separator, $string);
        } else {
            $result = explode($separator, $string, $limit);
        }
        return $result;
    }
public function split ( $ string , $ separator = null , $ limit = null ) { $ string = ( string ) $ string ; if ( $ separator === null ) { return [ $ string ] ; } if ( $ separator === '' ) { $ result = str_split ( $ string ) ; if ( $ limit !== null ) { $ result = array_slice ( $ result , 0 , $ limit ) ; } return $ result ; } if ( $ limit === null ) { $ result = explode ( $ separator , $ string ) ; } else { $ result = explode ( $ separator , $ string , $ limit ) ; } return $ result ; }
Split a string by a separator

Example::

String.split("My hovercraft is full of eels", " ") == ['My', 'hovercraft', 'is', 'full', 'of', 'eels']
String.split("Foo", "", 2) == ['F', 'o']

Node: This implementation follows JavaScript semantics without support of regular expressions.

@param string $string The string to split
@param string $separator The separator where the string should be splitted
@param integer $limit The maximum amount of items to split (exceeding items will be discarded)
@return array An array of the splitted parts, excluding the separators
Split a string by a separator