Not sure why you'd need 30 lines of messy code with strpos()... wouldn't this do the basic trick?
$all = file( 'myfile.txt' );
$selects = array();
foreach( $all as $line )
if( strpos( $line, 'SELECT' ) !== false && strpos( $line, 'FROM' ) !== false )
$selects[] = $line;
But... here is an (untested) regexp that should fetch from each SELECT to the end of the line into $selects[0]:
$text = file_get_contents( 'myfile.txt' );
$selects = array();
$count = preg_match_all( "/SELECT\s+.*?FROM.*?$/", $text, $selects );
This all assumes your queries do not span multiple lines... things get more complicated if they do.