3v4l.org

run code in 500+ PHP versions simultaneously
<?php $queries=" SELECT col1,col2,col3 FROM users WHERE id IN (1,2,3,4); SELECT * FROM references WHERE status = 1 ; SELECT a.col1 , a.col2 , b.col1 FROM table_a a | <--- Here is the caret, run this query INNER JOIN table_b b ON b.id_table_a = a.id WHERE a.id = 5 ; UPDATE table_a SET col1 = 'demo' WHERE id = 3; -- etc, etc, etc"; $rtrimmed=substr($queries,0,strpos($queries,'|')); // remove substr following pipe $ltrimmed=substr($rtrimmed,strrpos($rtrimmed,';')+1); // remove substr upto latest semicolon echo trim($ltrimmed); // remove whitespace on either side echo "\n---\n"; echo preg_match('~;\s*\K[^;|]*?(?= *\|)~',$queries,$out) ? $out[0] : '';
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
SELECT a.col1 , a.col2 , b.col1 FROM table_a a --- SELECT a.col1 , a.col2 , b.col1 FROM table_a a

preferences:
102.14 ms | 1408 KiB | 4 Q