在PHP中,速度更快:preg_split或explode? [英] In PHP, which is faster: preg_split or explode?
本文介绍了在PHP中,速度更快:preg_split或explode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这听起来像是一个愚蠢的问题,但是:使用它在php的搜索查询中提取关键字时,这样做会更快:
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']);
或
$keyword = explode(' ', $_GET['search']);
推荐答案
提示如果您不需要正则表达式的功能,则可以选择更快(虽然更简单)的替代方法,例如explode()或str_split().
Tip If you don't need the power of regular expressions, you can choose faster (albeit simpler) alternatives like explode() or str_split().
这篇关于在PHP中,速度更快:preg_split或explode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文