Encode Params - Post parameter encoding

Encodes an array to be sent along w/ a post request

<?
	function encodeParams($params) {
		if (is_array($params)) {
			$s = "";

			foreach ($params as $key => $val) {
				switch ($key) {
					default:
						$s .= $key . "=" . urlencode($val) . "&";
						break;
				}
			}
			
			return substr($s, 0, -1);
		} else {
			return "";
		}
	}
?>

Usage

Just pass the array of params to the function and get your encoded string ready to post returned.


Comments

Add your comment