PHP case-insensitive explode()

自闭症网瘾萝莉.ら 提交于 2019-12-01 16:09:43
Michael Robinson

Just use preg_split() and pass the flag i for case-insensitivity:

$keywords = preg_split("/your delimiter/i", $text);

Also make sure your delimiter which you pass to preg_split() doesn't cotain any sepcial regex characters. Otherwise make sure you escape them properly or use preg_quote().

explode('delimiter',strtolower($snippet));
  1. Never use expensive regular expressions when more CPU affordable functions are available.

  2. Never use double-quotes unless you explicitly have a use for mixing variables inside of strings.

You can first replace the delimiter and then use explode as normal. This can be done as a fairly readable one liner like this:

explode($delimiter,str_ireplace($delimiter,$delimiter,$snippet));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!