php---如何在命令行下运行PHP脚本[带参数]
创建一个简单的文本文件,其中包含有以下PHP代码,并把它保存为hello.php: <?php echo "Hello from the CLI"; ?> 现在,试着在命令行提示符下运行这个程序,方法是调用CLI可执行文件并提供脚本的文件名: #php phphello.php 输出Hello from the CLI ----------------- 使用标准的输入和输出 你可以在自己的PHP脚本里使用这三个常量,以接受用户的输入,或者显示处理和计算的结果。要更好地理解这一点,可以看看下面的脚本( 列表A): 列表A <?php // ask for input fwrite(STDOUT, "Enter your name: "); // get input $name = trim(fgets(STDIN)); // write input back fwrite(STDOUT, "Hello, $name!"); ?> Look what happens when you run it: shell> php hello.php Enter your name: Joe Hello, Joe! 在这个脚本里,fwrite()函数首先会向标准的输出设备写一条消息,询问用户的姓名。然后它会把从标准输入设备获得的用户输入信息读 取到一个PHP变量里,并它把合并成为一个字符串