<?php
fwrite(STDOUT, "Enter name:");
$name = trim(fgets(STDIN));
fwrite(STDOUT, "Hi, $name\n\n");
var_dump($argc);
var_dump($argv);
结果
stefan321@Lius-MacBook$ php test.php "hello world\!" 123 "hi~ stefan321"
Enter name:stefan321
Hi, stefan321
int(4)
array(4) {
[0]=>
string(8) "test.php"
[1]=>
string(13) "hello world\!"
[2]=>
string(3) "123"
[3]=>
string(13) "hi~ stefan321"
}
[img]http://dl.iteye.com/upload/attachment/0072/1188/fc7ad239-ed02-3779-8d3e-6588d9641d8f.png[/img]