Skip to content

Instantly share code, notes, and snippets.

@3emad
Created July 12, 2013 18:48
Show Gist options
  • Save 3emad/5986787 to your computer and use it in GitHub Desktop.
Save 3emad/5986787 to your computer and use it in GitHub Desktop.
A Regex in php that grabs all the quries that are defined.
chdir('/var/www/website');
$matchingTable = 'sometable';
$regex = 'SELECT(\n|\s|\w|.)*?(?='.$matchingTable.')(\n|\s|\w|.)*?(?=(\'|");)'; // could change to update or delete
$filepaths = glob('*.*');
foreach($filepaths as $filepath){
if(!file_exists(realpath($filepath))){
echo $filepath.PHP_EOL;
continue;
}
// grab all quries from those files
preg_match_all('/'.$regex.'/', file_get_contents(realpath($filepath)),$queries);
$queries = $queries[0];
foreach($queries as $query){
echo str_pad($filepath,60).' - '.$query.PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment