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

前端 未结 3 1243
半阙折子戏
半阙折子戏 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:07

    I found this blog that has run some testes regarding your question, the result was:

    • strpos() is 3-16 times faster than preg_match()
    • stripos() is 2-30 times slower than strpos()
    • stripos() is 20-100 percent faster than preg_match() with the caseless modifier "//i"
    • using a regular expression in preg_match() is not faster than using a long string
    • using the utf8 modifier "//u" in preg_match() makes it 2 times slower

    The code used was:

提交回复
热议问题