The manual says for split:
split — Split string into array by regular expression
So, making split deprecated and tell users to use preg_split instead makes total sense, since split() essentially was the same, but had a different name.
Explode is something different entirely since -as you said- it doesn’t use regular expressions.
If you just want to chop a string at each space I would stick with explode() if I were you; it should be faster than preg_split() for this purpose.
I ran a (small) benchmark to explode the first paragraph of Lorem Ipsum 10.000 times, once using explode() and once using preg_split()
These are the results:
explode: 0.287669897079 seconds
preg_split: 1.02503013611 seconds
So, explode() is about 4 times as fast as preg_split().
I benchmarked on a machine running PHP 5.2.6, but these results should be roughly the same for PHP 5.3.x
Benchmark code:
class Stopwatch
{
private $_starttime;
/**
* Constructor
*/
function __construct() {}
/**
* Start the stopwatch
*/
public function start()
{
$mtime = microtime();
list($usec, $sec) = split(' ', $mtime);
$this->_starttime = (float)$usec + (float)$sec;
}
/**
* Return the current runtime (doesn't actually "stop" the stopwatch, but returns current running time, like "split time" on irl stopwatches)
* @return float Time the stopwatch has run (in seconds)
*/
public function stop()
{
$mtime = microtime();
list($usec, $sec) = split(' ', $mtime);
return (((float)$usec + (float)$sec) - (float)$this->_starttime);
}
}
$str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ultricies enim nec nisl tincidunt a ultricies metus ultrices. Cras nisi libero, posuere semper consequat id, mattis pretium diam. Sed porta ornare malesuada. Integer tempor lectus a risus consequat nec sodales nunc luctus. Mauris vel dolor massa. Pellentesque tempor sapien ut orci commodo luctus. Aliquam eleifend tempor suscipit. Proin in arcu velit. Fusce risus lorem, mattis et dignissim vitae, euismod vitae purus. Duis sed lectus sem, vitae eleifend tortor. Nulla interdum sagittis lacus sit amet varius. Proin consequat ultrices hendrerit. Quisque eget tortor a tortor facilisis hendrerit a sed ligula. Fusce vel ipsum erat, a rutrum felis. Etiam euismod fermentum tortor sit amet pharetra. Vestibulum placerat scelerisque ipsum eget posuere.';
$s = new Stopwatch;
$s->start();
for ($i=0; $i<10000;$i++)
{
$x = explode(' ', $str);
}
echo $s->stop();
echo '<br/>';
$s->start();
for ($i=0; $i<10000;$i++)
{
$x = preg_split('/\\s/', $str);
}
echo $s->stop();