更新时间:2023-08-28 17:12:34
在文件系统上处理文件的简单方法:
A simple way with the file on the filesystem:
<?php
$path = "file.txt";
$content = file($path); // Parse file into an array by newline
$data = array_pop($content);
if (trim($data) == '?>') {
$content[] = 'echo "... again";';
$content[] = "\n$data";
file_put_contents($path, implode($content));
}
是哪个.
$ cat file.txt
<?php
echo 'Hello world';
?>
$ php test.php
$ cat file.txt
<?php
echo 'Hello world';
echo "... again";
?>