note 39429 added to function.implode
| From: | mbirthatwebwritersdotde at rn2 dot php dot net | Date: | Wed, 28 Jan 2004 12:45:09 +0000 |
| Subject: | note 39429 added to function.implode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64312@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.implode.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39429
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39429&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39429&report=yes
Search -- http://master.php.net/manage/user-notes.php