In PHP, which is faster: preg_split or explode?

Marco picture Marco · Dec 4, 2014 · Viewed 14.1k times · Source

This may sound like a stupid question, but: which is faster when using it to extract keywords in a search query in php:

$keyword = preg_split('/[\s]+/', $_GET['search']);

or

$keyword = explode(' ', $_GET['search']);

Answer

Machavity picture Machavity · Dec 4, 2014

Explode is faster, per PHP.net

Tip If you don't need the power of regular expressions, you can choose faster (albeit simpler) alternatives like explode() or str_split().