note 39429 deleted from function.implode by irchtml
| From: | irchtml@php.net | Date: | Tue, 06 Apr 2004 23:20:51 +0000 |
| Subject: | note 39429 deleted from function.implode by irchtml | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-67741@lists.php.net to get a copy of this message | ||
Note Submitter: mbirth at webwriters dot de
----
I found it useful to have an implode-version which returns a string which can be directly used for
URLs. So the following array:
<?
$params = array('lang' => 'de', 'show' => '1',
'testäöü' => 'successful');
?>
would be returned as
?lang=de&show=1&test%E4%F6%FC=successful
------------------------------------
<?php
/*
* Returns a string with imploded array-elements like ?key1=value1&key2=value2
* if array is empty or no array, it will return an empty string
*/
function httpimplode($aryInput, $quma = true) {
if (is_array($aryInput) && count($aryInput)>0) {
if ($quma == true) {
$result = '?';
} else {
$result = '';
}
foreach ($aryInput as $key=>$value) {
if (strlen($result)>1) {
$result .= '&';
}
$result .= urlencode($key) . '=' . urlencode($value);
}
} else {
$result = '';
}
return $result;
}
?>