[thelist] functions in PHP and arguments (was: PHP string tip ...)

Ray Hill ray at opengrid.com
Fri Aug 31 18:14:51 CDT 2001


Hmmm.  The last project I worked on had something like this (in an in-house
language very similar to PHP).  I'm not sure what the syntax for the loop
was like, but here's how it acted.  It was for building the query string
after the ? un system URLs.  It's more or less the same as Jeff's example,
except that the array is inside the function instead of outside.

Variables were all passes in as a comma delimited string, as such:

	<?
	// Set from the original URL or session
	$sessionid = "465432168";
	$subsection = "foo";
	?>
	.....
	<a href="/URL<? qstring("page,one,subsection," . $subsection);
?>">Link</a>

So the funcion was expectign just one argument, but would then split that at
the commas and deal with the variables from there.

	<?
	function qstring($args) {
		print("?sessionid=" . $sessionid);
		// Split $args into an array.
			// Loop through the arguments two at a time, pairing

			// them off as query string arguments.
			print("&" . $argOdd . "=" . $argEven);
	}
	?>

So the above link would end up looking like this on output:

	<a href="/URL?sessionid=465432168&page=one&subsection=foo">Link</a>


Hope that helps...


--ray




More information about the thelist mailing list