开发者

Finding a specific set of first two words of long string

开发者 https://www.devze.com 2023-03-20 07:14 出处:网络
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 somethin

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

精彩评论

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