<?php // check for all required arguments // first argument is always name of script! if ($argc != 4) { die("Usage: book.php <check-in-date> <num-nights> <room-type> "); }
// remove first argument array_shift($argv);
// get and use remaining arguments $checkin = $argv[0]; $nights = $argv[1]; $type = $argv[2]; echo "You have requested a $type room for $nights nights, checking in on $checkin. Thank you for your order! "; ?>
下面是其用法的示例:
shell> php phpbook.php 21/05/2005 7 single You have requested a single room for 7 nights, checking in on 21/05/2005. Thank you for your order!