public static function multiExplode($string, array $delimiters, $keepDelimiters = true)
    {
        if ($keepDelimiters === true) {
            // Ensure special characters are escaped
            foreach ($delimiters as &$delimiter) {
                $delimiter = preg_quote($delimiter);
            }

            // RegEx fragment with delimiters
            $fragment = implode('|', $delimiters);
            $regEx = sprintf('@(?<=%s)@', $fragment);
            return preg_split($regEx, $string, -1, PREG_SPLIT_DELIM_CAPTURE);

        } else {

            $string = str_replace($delimiters, $delimiters[0], $string);
            return explode($delimiters[0], $string);
        }
    }
public static function multiExplode($string, array $delimiters, $keepDelimiters = true)
    {
        if ($keepDelimiters === true) {
            // Ensure special characters are escaped
            foreach ($delimiters as &$delimiter) {
                $delimiter = preg_quote($delimiter);
            }

            // RegEx fragment with delimiters
            $fragment = implode('|', $delimiters);
            $regEx = sprintf('@(?<=%s)@', $fragment);
            return preg_split($regEx, $string, -1, PREG_SPLIT_DELIM_CAPTURE);

        } else {

            $string = str_replace($delimiters, $delimiters[0], $string);
            return explode($delimiters[0], $string);
        }
    }
public static function multiExplode ( $ string , array $ delimiters , $ keepDelimiters = true ) { if ( $ keepDelimiters === true ) { // Ensure special characters are escaped foreach ( $ delimiters as & $ delimiter ) { $ delimiter = preg_quote ( $ delimiter ) ; } // RegEx fragment with delimiters $ fragment = implode ( '|' , $ delimiters ) ; $ regEx = sprintf ( '@(?<=%s)@' , $ fragment ) ; return preg_split ( $ regEx , $ string , - 1 , PREG_SPLIT_DELIM_CAPTURE ) ; } else { $ string = str_replace ( $ delimiters , $ delimiters [ 0 ] , $ string ) ; return explode ( $ delimiters [ 0 ] , $ string ) ; } }
Explodes a string into array supporting several delimiters

@param string $string
@param array $delimiters A collection of delimiters
@param boolean $keepDelimiters Whether to keep delimiters on exploding
@return array
Explodes a string into array supporting several delimiters