开发者

Finding a specific set of first two words of long string

Right now I have a check in place that analyzes the first word of a string like so:

if( strtolower( stristr(  preg_replace( '/\s+/', ' ', trim($sql) ), ' ', true )  ) == 'select'){ //do something }

Now I would like to check for the first two words t开发者_高级运维o be == strtolower('SELECT SQL_CALC_FOUND_ROWS') However my original code only analyzes the very first word. How can I fix this?


Using regular expressions seems overkill for this task, you can just use strpos to check if a string containing the two words is at the start of the string you're checking (position 0),

if (strpos(strtolower($sql), "select sql_calc_found_rows") === 0) { ... }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜