home

Quickies, by Andrea Olivato

text

Retrieve Options like Bash in Php : getopt()

Simply retrieve and use Options passed from command line to php

#!/usr/bin/php

<?php
	/* 
		@ Options without ":" do not accept any argument
		@ Options with a single ":" require an argument. 
			No argument input will cause an error
		@ Options with a double "::" accept an argument. 
			No argument input won't cause any error
	*/
	$shortopts = "vhr:o::"; 

	/* 
		Behave of longopts is exactly the 
		same of short ones
	*/

	$longopts  = array(
		"verbose",        
		"help",   
		"required:",     
		"optional::",    
	);

	$options = getopt($shortopts, $longopts);

	var_dump($options);

?>

3 years ago

May 15, 2009
php
Comments (View)
blog comments powered by Disqus