note 71587 added to function.array-search

From: Date: Wed, 06 Dec 2006 23:25:27 +0000
Subject: note 71587 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-120353@lists.php.net to get a copy of this message
You can use array_search to simply parse a CLI program's input parameters such as: [user@server ~]$ ./someCLIprog.php --username user1 --password 123password --option1 whatever You can easily parse this information using the following code snippets: <?php // Get the username $userkey = array_search("--username", $argv); // Make sure both that the token was found and followed by another valid token, AKA not one that begins with a - if ($userkey && !empty($argv[$userkey+1]) && strcmp($argv[$userkey+1]{0} != '-')) { $username = $argv[$userkey+1]; } // If you want the token to be required add the following else statement else { exit("No username provided\n"); } // repeat for each optional parameter, ?> ---- Server IP: 64.71.164.2 Probable Submitter: 205.158.200.226 ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- https://master.php.net/note/edit/71587 Del: integrated -- https://master.php.net/note/delete/71587/integrated Del: useless -- https://master.php.net/note/delete/71587/useless Del: bad code -- https://master.php.net/note/delete/71587/bad+code Del: spam -- https://master.php.net/note/delete/71587/spam Del: non-english -- https://master.php.net/note/delete/71587/non-english Del: in docs -- https://master.php.net/note/delete/71587/in+docs Del: other reasons-- https://master.php.net/note/delete/71587 Reject -- https://master.php.net/note/reject/71587 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120353) next »