在多个 php 文件中添加一行代码


Add a line of code in multiple php file

我有超过数百个具有不同代码的 php 文件,我想在我们的所有 php 文件中添加几行代码,例如我们有 1.php, 2.php, 3.php and so on... 个文件,我想添加一个 php 包含函数

<?php 'include common.php'; ?>

到我所有的 php 文件中,我也可以手动将此代码添加到我的所有 php 文件中,但这需要很多时间。那么我该怎么做呢?我正在使用Windows操作系统,所以请帮助我们。

您可以尝试如下 bash 脚本(假设路径中没有空格)

for file in $(find . -name "*php"); do
  echo "<?php 'include common.php'; ?>" > temp.txt
  cp $file $file.bakcup
  cat $file >> temp.txt
  mv temp.txt $file
done