Return to Snippet

Revision: 47600
at June 11, 2011 02:44 by anagaiyahoocom


Initial Code
/**
	* Remove key/value pair from url query string
	*
	* @param $qry string Query String
	* @param $key string Query key to remove
	* @return string Modified query string
	* @static
	*/
	  
	function removeQueryVal($qry,$qryKey)
	{
		$qry_new = '';
		
		if(strlen($qry)>1)
		{
			$qry = (strpos($qry,"?")!==false) ? substr($qry,1) : $qry;
			
			$qryArr = (strpos($qry,'&')!==false) ? explode("&",$qry) : $qry;
				
			//build query array with removed $key value
			foreach($qryArr as $val)
			{
				//ignore $key query value
				if(strpos($val,$qryKey.'=')===false)
				{
					$qryPair = explode('=',$val);
					$qryval[$qryPair[0]] = $qryPair[1];
				}
			}
									
			//rebuild new query string
			foreach($qryval as $key=>$val)
			{
				$qry_new .= '&'.$key.'='.$val;
			}
			$qry_new = substr($qry_new,1);

			$qry_new = ($qry_new) ? '?'.$qry_new : '';
		}
		
		return $qry_new;
	}

Initial URL

                                

Initial Description

                                

Initial Title
Delete key=value from url query string

Initial Tags
php

Initial Language
PHP