cvs: pear /Net_URL URL.php
| From: | Richard Heyes | Date: | Thu, 03 Oct 2002 13:03:32 +0000 |
| Subject: | cvs: pear /Net_URL URL.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-6834@lists.php.net to get a copy of this message | ||
richard Thu Oct 3 09:03:32 2002 EDT
Modified files:
/pear/Net_URL URL.php
Log:
Added patch from Alexey Borzov to allow arrays in addQueryString()
Index: pear/Net_URL/URL.php
diff -u pear/Net_URL/URL.php:1.17 pear/Net_URL/URL.php:1.18
--- pear/Net_URL/URL.php:1.17 Sat Sep 28 20:16:08 2002
+++ pear/Net_URL/URL.php Thu Oct 3 09:03:32 2002
@@ -121,7 +121,7 @@
$this->host = !empty($host) ? $host :
(isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] :
'localhost');
$this->port = !empty($port) ? $port :
(isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] :
80);
$this->path = $HTTP_SERVER_VARS['PHP_SELF'];
- $this->querystring =
isset($HTTP_SERVER_VARS['QUERY_STRING'])?$this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']):'';
+ $this->querystring =
$this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']);
$this->anchor = '';
// Parse the uri and store the various parts
@@ -202,11 +202,16 @@
* @param $name Name of item
* @param $value Value of item
* @param $preencoded Whether value is urlencoded or not, default = not
- * @access public<>
+ * @access public
*/
function addQueryString($name, $value, $preencoded = false)
{
$this->querystring[$name] = $preencoded ? $value : urlencode($value);
+ if ($preencoded) {
+ $this->querystring[$name] = $value;
+ } else {
+ $this->querystring[$name] = is_array($value)? array_map('urlencode',
$value): urlencode($value);
+ }
}
/**
@@ -241,20 +246,19 @@
*/
function getQueryString()
{
- if (!empty($this->querystring) &&
- is_array($this->querystring)) {
+ if (!empty($this->querystring)) {
foreach ($this->querystring as $name => $value) {
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- $querystring[] = sprintf('%s[%s]=%s', $name, $k, $v);
- }
- } else {
- $querystring[] = $name . '=' . $value;
- }
+ if (is_array($value)) {
+ foreach ($value as $k => $v) {
+ $querystring[] = sprintf('%s[%s]=%s', $name, $k, $v);
+ }
+ } else {
+ $querystring[] = $name . '=' . $value;
+ }
}
$querystring = implode('&', $querystring);
} else {
- $querystring = $this->querystring;
+ $querystring = '';
}
return $querystring;
@@ -271,19 +275,18 @@
{
parse_str($querystring, $qs);
- if (!$qs) return $querystring;
foreach ($qs as $key => $value) {
- if (is_array($value)) {
- foreach ($value as $k => $v) {
- $value[$k] = rawurlencode($v);
- }
- $qs[$key] = $value;
- } else {
- $qs[$key] = rawurlencode($value);
- }
+ if (is_array($value)) {
+ foreach ($value as $k => $v) {
+ $value[$k] = rawurlencode($v);
+ }
+ $qs[$key] = $value;
+ } else {
+ $qs[$key] = rawurlencode($value);
+ }
}
return $qs;
}
}
-?>
+?>
\ No newline at end of file