note 70134 added to function.parse-url

From: Date: Wed, 04 Oct 2006 16:48:03 +0000
Subject: note 70134 added to function.parse-url
Groups: php.notes 
Request: Send a blank email to php-notes+get-118035@lists.php.net to get a copy of this message
With few modifications /** * source: http://us2.php.net/manual/en/function.parse-url.php#60237 * Edit the Query portion of an url * * @param string $action ethier a "+" or a "-" depending on what action you want to perform * @param mixed $var array (+) or string (-) * @param string $uri the URL to use. if this is left out, it uses $_SERVER['PHP_SELF'] * @version 1.0.0 */ function change_query($action, $var = NULL, $uri = NULL) { if (($action == "+" && !is_array($var)) || ($action == "-" && $var == "") || $var == NULL) { return FALSE; } if (is_null($uri)) { $uri = $_SERVER['REQUEST_URI']; } $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; break; case '-': if (isset($vals[$var])) { unset($vals[$var]); } break; default: break; } foreach ( $vals as $k=>$value) { $vals[$k] = urlencode($value); } $result = $beginning . (count($vals) ? '?'.implode("&", $vals) : ''); return $result; } ---- Server IP: 64.71.164.2 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/70134 Del: integrated -- https://master.php.net/note/delete/70134/integrated Del: useless -- https://master.php.net/note/delete/70134/useless Del: bad code -- https://master.php.net/note/delete/70134/bad+code Del: spam -- https://master.php.net/note/delete/70134/spam Del: non-english -- https://master.php.net/note/delete/70134/non-english Del: in docs -- https://master.php.net/note/delete/70134/in+docs Del: other reasons-- https://master.php.net/note/delete/70134 Reject -- https://master.php.net/note/reject/70134 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#118035) next »