Shell - CLI / PHP | Terminal flags

Wednesday, October 31st, 2018 | Coding

Method for receiving Command Line Interface ( CLI ) variables in a PHP script:

Example: script.php -a 'hello' -b 'yes'

< ?php

	$a = $argv;
	$b = array();
	
	if (count($a) != 0) {
		
		foreach ($a as $arg){
		   list($x,$y) = explode('=', $arg);
		   $b["$x"]    = $y;  
		}
		
		$tweet = $b['tweet'];
		$authorized = $b['authorized'];
	
	}
	
	print_r($tweet);
	
? >


Comments


E19 Creative

Products | Support | About | Contact | Login