一个名为"hello.php"的示例脚本:
<?php
// Hello
echo "Hello World";
?>
在linux下,我们可以执行:
php-s hello.php>hello.php
我们可以看到下一个:
<code><span style="color: #000000">...
如果没有PHP-CLI添加的HTML,我如何获得原始脚本的源代码(包括注释)?,我看到了参数"-w",但是注释和空白都被去掉了。
谢谢!
您可以使用-r
选项来运行PHP命令,然后让命令打印脚本的内容:
php -r 'readfile("hello.php");'
或者更一般地说:
php -r 'foreach (array_slice($argv, 1) as $file) { readfile($file); }' hello.php somefile.txt
注意,它将打印任何文件,它不必是PHP脚本。
这个shell命令将完成您想要的任务:
$ cat hello.php > hello.php