【问题标题】:How can I check if specific file be used in php project and linux environment如何检查特定文件是否在 php 项目和 linux 环境中使用
【发布时间】:2020-10-11 21:42:21
【问题描述】:

目前我想检查php项目中是否使用了特定文件

$target = "foobar.php";
$ beUsed = checkFile($target);
  
function checkFile($target){
    //code to check be here
    if (beUsed) return true;
    return false;
}

感谢您的阅读,任何帮助将不胜感激

【问题讨论】:

  • 您要搜索项目中使用的文件吗?
  • 是的,我想搜索要在 php 项目中使用的文件。
  • 我尝试过,但这不是我的正确答案。我想检查一个文件是否在所有项目的另一个文件中使用或需要。
  • All 项目中?

标签: php linux


【解决方案1】:

你可以使用linux命令

$target = "foobar.php";

searchFile($target);


function searchFile($target){
    $file_name = basename(__FILE__);

    $cmd = sprintf("grep -r --exclude='%s' %s ./* ",$file_name, $target);

    $res = exec($cmd);

    if($res){
        echo "Exists!" . PHP_EOL;

        print_r($res);

        return true;
    }

    return false;
}

【讨论】:

    猜你喜欢
    • 2014-03-16
    • 1970-01-01
    • 1970-01-01
    • 2012-06-28
    • 2022-11-21
    • 1970-01-01
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多