ParseArgs-Talk

Summary: Talk page for ParseArgs.
Maintainer: Petko (original author: Pm)
Users: (View? / Edit?)

This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.

I am using a more generic version of this function, which I think is more flexible/customizable without any additional overhead. Here is the code:

function ParseArgs_YAG($x,
                       $optpat = "(?>(\\w+)\\s*[:=]\\s*)",
                       $valpat = "(\"[^\"]*\"|'[^']*'|[^,;]+|\\S+)",
                       $stripquotepat = "/^\\s*(['\"])?(.*)\\1\\s*[,;]?\\s*$/"  )
{
	$z = array();
	preg_match_all("/($optpat|[-+])$valpat/", $x, $terms, PREG_SET_ORDER);
	foreach($terms as $t)
	{
		$v = preg_replace($stripquotepat, '$2', $t[3]);
		if ($t[2]) { $z['#'][] = $t[2]; $z[$t[2]] = $v; }
		else { $z['#'][] = $t[1]; $z[$t[1]][] = $v; }
		$z['#'][] = $v;
	}
	return $z;
}

One can specify the delimiter (other than white space) and whether or not to strip those in the final value. In the above default values ',' and ';' are used as delimiters besides whitespaces. Subhrajit July 20, 2010, at 01:34 PM

Talk page for the ParseArgs recipe (users?).