note 70205 added to function.parse-url

From: Date: Fri, 06 Oct 2006 17:37:32 +0000
Subject: note 70205 added to function.parse-url
Groups: php.notes 
Request: Send a blank email to php-notes+get-118135@lists.php.net to get a copy of this message
There was a typo in change_query Here is the corrected version function change_query($action, $var = NULL, $uri = NULL) { if (($action == "+" && !is_array($var)) || ($action == "-" && $var == "") || $var == NULL) { return FALSE; } if (is_null($uri)) { //Piece together uri string $beginning = $_SERVER['PHP_SELF']; $ending = (isset ($_SERVER['QUERY_STRING'])) ? $_SERVER['QUERY_STRING'] : ''; } else { $qstart = strpos($uri, '?'); if ($qstart === false) { $beginning = $uri; //$ending is '' anyway $ending = ""; } else { $beginning = substr($uri, 0, $qstart); $ending = substr($uri, $qstart); } } $vals = array (); $ending = str_replace('?', '', $ending); parse_str($ending, $vals); switch ($action) { case '+' : $vals[$var[0]] = $var[1]; break; case '-' : if (isset ($vals[$var])) { unset ($vals[$var]); } break; default : break; } $params = array(); foreach ($vals as $k => $value) { $params[] = $k."=".urlencode($value); } $result = $beginning . (count($params) ? '?' . implode("&", $params) : ''); return $result; } ---- Server IP: 216.194.113.175 Probable Submitter: 216.254.105.224 ---- Manual Page -- http://www.php.net/manual/en/function.parse-url.php Edit -- https://master.php.net/note/edit/70205 Del: integrated -- https://master.php.net/note/delete/70205/integrated Del: useless -- https://master.php.net/note/delete/70205/useless Del: bad code -- https://master.php.net/note/delete/70205/bad+code Del: spam -- https://master.php.net/note/delete/70205/spam Del: non-english -- https://master.php.net/note/delete/70205/non-english Del: in docs -- https://master.php.net/note/delete/70205/in+docs Del: other reasons-- https://master.php.net/note/delete/70205 Reject -- https://master.php.net/note/reject/70205 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118135) next »