public function split($pattern, $limit = null, $quote = true)
    {
        // Not sure why you would do this but your wish is our command :)
        if ($limit === 0) return [];

        // UTF8::split errors when supplied an empty pattern in < PHP 5.4.13
        // and current versions of HHVM (3.8 and below)
        if ($pattern === '') return [$this->newSelf($this->scalarString)];

        // UTF8::split returns the remaining unsplit string
        // in the last index when supplying a limit.
        if ($limit > 0)
        {
            $limit += 1;
        }
        else
        {
            $limit = -1;
        }

        // TODO: As per the above comments, all well and good but we are not
        // using UTF8::split here, we are using preg_split???

        // Build the expression
        $expression = $this->regexDelimiter;

        if ($quote === true)
        {
            $expression .= preg_quote($pattern, $this->regexDelimiter);
        }
        else
        {
            $expression .= $pattern;
        }

        $expression .= $this->regexDelimiter.'u';

        // Split the string
        $array = preg_split($expression, $this->scalarString, $limit);

        // Remove any remaining unsplit string.
        if ($limit > 0 && count($array) === $limit) array_pop($array);

        return $this->newSelfs($array);
    }
public function split($pattern, $limit = null, $quote = true)
    {
        // Not sure why you would do this but your wish is our command :)
        if ($limit === 0) return [];

        // UTF8::split errors when supplied an empty pattern in < PHP 5.4.13
        // and current versions of HHVM (3.8 and below)
        if ($pattern === '') return [$this->newSelf($this->scalarString)];

        // UTF8::split returns the remaining unsplit string
        // in the last index when supplying a limit.
        if ($limit > 0)
        {
            $limit += 1;
        }
        else
        {
            $limit = -1;
        }

        // TODO: As per the above comments, all well and good but we are not
        // using UTF8::split here, we are using preg_split???

        // Build the expression
        $expression = $this->regexDelimiter;

        if ($quote === true)
        {
            $expression .= preg_quote($pattern, $this->regexDelimiter);
        }
        else
        {
            $expression .= $pattern;
        }

        $expression .= $this->regexDelimiter.'u';

        // Split the string
        $array = preg_split($expression, $this->scalarString, $limit);

        // Remove any remaining unsplit string.
        if ($limit > 0 && count($array) === $limit) array_pop($array);

        return $this->newSelfs($array);
    }
public function split ( $ pattern , $ limit = null , $ quote = true ) { // Not sure why you would do this but your wish is our command :) if ( $ limit === 0 ) return [ ] ; // UTF8::split errors when supplied an empty pattern in < PHP 5.4.13 // and current versions of HHVM (3.8 and below) if ( $ pattern === '' ) return [ $ this -> newSelf ( $ this -> scalarString ) ] ; // UTF8::split returns the remaining unsplit string // in the last index when supplying a limit. if ( $ limit > 0 ) { $ limit += 1 ; } else { $ limit = - 1 ; } // TODO: As per the above comments, all well and good but we are not // using UTF8::split here, we are using preg_split??? // Build the expression $ expression = $ this -> regexDelimiter ; if ( $ quote === true ) { $ expression .= preg_quote ( $ pattern , $ this -> regexDelimiter ) ; } else { $ expression .= $ pattern ; } $ expression .= $ this -> regexDelimiter . 'u' ; // Split the string $ array = preg_split ( $ expression , $ this -> scalarString , $ limit ) ; // Remove any remaining unsplit string. if ( $ limit > 0 && count ( $ array ) === $ limit ) array_pop ( $ array ) ; return $ this -> newSelfs ( $ array ) ; }
Splits the string with the provided regular expression.

@param  string   $pattern The regex with which to split the string.

@param  int|null $limit   Optional maximum number of results to return.

@param  bool     $quote   By default this method will run the provided
$pattern through preg_quote(), this allows the
method to be used to split on simple substrings.

@return static[]          An array of Str objects.
Splits the string with the provided regular expression .