【发布时间】:2018-08-24 03:30:39
【问题描述】:
我正在用 PHP 编写一个简单的 cmets 删除脚本。我想做的是为同一目录中的所有文件循环整个脚本。在这一点上,我不关心子目录或子文件夹。此示例只有 1 个文件。我知道我们需要做一个 do..while 循环,但正确的语法是什么?
<?php
$file='home.html';
$page = file_get_contents($file);
$current = preg_replace('<!--[^\[](.*?)-->', '', $page);
file_put_contents($file, $current);
echo $current;
?>
我有一个包含 *.html 文件的文件夹,因此该脚本将读取每个带有 *.html 扩展名的文件并应用 preg_replace。
提前致谢!
V
【问题讨论】:
-
看看glob
标签: php while-loop file-get-contents file-put-contents