Search code examples
phpexplodepreg-split

In PHP, which is faster: preg_split or explode?


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']);

Solution

  • 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().