which is the fast process strpos()/stripos() or preg_match() in php

前端 未结 3 1228
半阙折子戏
半阙折子戏 2021-01-01 05:16

I just want to known which one will be fast of strpos()/stripos() or preg_match() functions in php.

3条回答
  •  有刺的猬
    2021-01-01 06:16

    Benchmarking is a tricky business, but it's fairly safe to say that preg_match is slower than strpos or stripos. This is because the PRCE functions implement a REGEX engine that is much more powerful and flexible than the string functions.

    They also do different things. strpos will tell you the index of the start of the string inside another string, whereas preg_match is mainly used to probe the format of a string, and to retrieve sections of it based on regular expressions.

    In short, if you simply want to find a string inside another string, use strpos or stripos.

提交回复
热议问题