使用“NO_EMPTY”选项进行爆炸,有助于获得更快的功能

Basically I have this string

$str="word1    word2   word3";

I need

array(
  'word1',
  'word2',
  'word3'
);

I made this function:

function explodeStrict($delimiter,$string) {
    return preg_split("/{$delimiter}/",$string,null,PREG_SPLIT_NO_EMPTY);
}

But I need it to be fast. And this function is 2x slower than a simple explode(); (within a 1mil loop)
I have tried a vanilla style parsing each chars but it gets 7x slower than the explode();

Can you imagine a function as fast as explode that ignores empty elements?

With my function a 1milion loop takes 3.9 sec. Explode take 2 sec

Thanks

$str = 'word1    word2   word3';
$str = strtok($str, ' ');

$x = array();
while ($str !== false)
{
  $x[] = $str;
  $str = strtok(' ');
}
function explodeStrict($delimiter,$string) {
    return preg_split("/" . preg_quote($delimiter, "/") . "+/", $string);
}

Given:

$str="word1    word2   word3";

Try:

return array_filter(explode(" ",$str));