note 108883 added to features.commandline

From: Date: Fri, 01 Jun 2012 01:17:31 +0000
Subject: note 108883 added to features.commandline
Groups: php.notes 
Request: Send a blank email to php-notes+get-188352@lists.php.net to get a copy of this message
You can easily parse command line arguments into the $_GET variable by using the parse_str() function. <?php parse_str(implode('&', array_slice($argv, 1)), $_GET); ?> It behaves exactly like you'd expect with cgi-php. $ php -f somefile.php a=1 b[]=2 b[]=3 This will set $_GET['a'] to '1' and $_GET['b'] to array('2', '3'). Even better, instead of putting that line in every file, take advantage of PHP's auto_prepend_file directive. Put that line in its own file and set the auto_prepend_file directive in your cli-specific php.ini like so: auto_prepend_file = "/etc/php/cli-php5.3/local.prepend.php" It will be automatically prepended to any PHP file run from the command line. ---- Server IP: 69.147.83.197 Probable Submitter: 72.95.54.104 ---- Manual Page -- http://www.php.net/manual/en/features.commandline.php Edit -- https://master.php.net/note/edit/108883 Del: integrated -- https://master.php.net/note/delete/108883/integrated Del: useless -- https://master.php.net/note/delete/108883/useless Del: bad code -- https://master.php.net/note/delete/108883/bad+code Del: spam -- https://master.php.net/note/delete/108883/spam Del: non-english -- https://master.php.net/note/delete/108883/non-english Del: in docs -- https://master.php.net/note/delete/108883/in+docs Del: other reasons-- https://master.php.net/note/delete/108883 Reject -- https://master.php.net/note/reject/108883 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188352) next »