All pastes #353496 Raw Edit

Mine

public text v1 · immutable
·published 2007-02-13 12:12 UTC
rendered paste body
<?php
	// Goal replace SELECT [anything] FROM with SELECT COUNT(*), and not effect the (SUB QUERY)

	// So the above should become SELECT COUNT(*) FROM table1 WHERE col1 = (SELECT col1 FROM table2 WHERE col3 = "some value")
	
	$query = 'SELECT col1, col2 FROM table1 WHERE col1 = (SELECT col1 FROM table2 WHERE col3 = "some value")';
	$pattern = '/^SELECT (.*) FROM ([^SELECT])/i';
	$replacement = 'SELECT COUNT(*) FROM ';
	echo preg_replace($pattern, $replacement, $query);


?>