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) { ... }
精彩评论