LoginSignup
1
1

More than 5 years have passed since last update.

PHPでand, or 演算子が使われてないか検索するワンライナー

Posted at
php -r 'foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($argv[1])) as $f) { if($f->isFIle() && substr($f, -4) == ".php") { foreach(token_get_all(file_get_contents($f)) as $t) {if(is_array($t) && ($t[0] == 263 or $t[0] == 265)){ echo $f, PHP_EOL;}}}}' .

windowsユーザはシングルクオートとダブルクオートは逆にしてね






おまけ:該当行表示版

find ./ -name "*.php" -exec php -r 'foreach(token_get_all(file_get_contents($argv[1])) as $t) { if (is_array($t) && in_array($t[0], [T_LOGICAL_OR, T_LOGICAL_AND])) {echo $t[2], "\t", $argv[1], PHP_EOL, file($argv[1])[$t[2] -1];}};' {} \;

実行結果

76      ./library/Zend/Filter/File/Decrypt.php
        if (file_exists($this->filename) and !is_writable($this->filename)) {
76      ./library/Zend/Filter/File/Encrypt.php
        if (file_exists($this->filename) and !is_writable($this->filename)) {
117     ./library/Zend/Filter/Encrypt/Openssl.php
            if (is_file($key) and is_readable($key)) {
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1