note 60551 added to function.urlencode

From: Date: Tue, 10 Jan 2006 23:30:27 +0000
Subject: note 60551 added to function.urlencode
Groups: php.notes 
Request: Send a blank email to php-notes+get-101521@lists.php.net to get a copy of this message
This very simple function makes an valid parameters part of an URL, to me it looks like several of the other versions here are decoding wrongly as they do not convert & seperating the variables into &. $vars=array('name' => 'tore','action' => 'sell&buy'); echo MakeRequestUrl($vars); /* Makes an valid html request url by parsing the params array * @param $params The parameters to be converted into URL with key as name. */ function MakeRequestUrl($params) { $querystring=null; foreach ($params as $name => $value) { $querystring=$name.'='.urlencode($value).'&'.$querystring; } // Cut the last '&' $querystring=substr($querystring,0,strlen($querystring)-1); return htmlentities($querystring); } Will output: action=sell%26buy&name=tore ---- Manual Page -- http://www.php.net/manual/en/function.urlencode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60551 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60551&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60551&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60551&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60551&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60551&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60551&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60551&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60551&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101521) next »