Created
July 12, 2013 18:48
-
-
Save 3emad/5986787 to your computer and use it in GitHub Desktop.
A Regex in php that grabs all the quries that are defined.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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