<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:series="http://unfoldingneurons.com/"
> <channel><title>Comments on: PHP Function:  Remove a Query String&#160;Key=&gt;Value</title> <atom:link href="http://davidwalsh.name/php-remove-variable/feed" rel="self" type="application/rss+xml" /><link>http://davidwalsh.name/php-remove-variable</link> <description>Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</description> <lastBuildDate>Wed, 23 May 2012 19:56:08 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: SHWEBDEV</title><link>http://davidwalsh.name/php-remove-variable#comment-31978</link> <dc:creator>SHWEBDEV</dc:creator> <pubDate>Tue, 01 May 2012 23:50:05 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-31978</guid> <description>Adam&#039;s example helped me to resolve a string building issue I was having with pagination of a search facility.Beware of the quotes in the examples provided as mentioned by Paul R, many of the examples i tested above required further modification, due to this website&#039;s output.</description> <content:encoded><![CDATA[<p>Adam&#8217;s example helped me to resolve a string building issue I was having with pagination of a search facility.</p><p>Beware of the quotes in the examples provided as mentioned by Paul R, many of the examples i tested above required further modification, due to this website&#8217;s output.</p> ]]></content:encoded> </item> <item><title>By: Paul R</title><link>http://davidwalsh.name/php-remove-variable#comment-31940</link> <dc:creator>Paul R</dc:creator> <pubDate>Sat, 28 Apr 2012 18:41:37 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-31940</guid> <description>I have two warnings for readers stumble across this article:1) Many of the code examples above gave syntax errors when I copied and pasted the code.  The syntax errors are caused by this webpage printing a single quotation mark as some other type of symbol that looks similar to a quote mark but is actually not.   To solve this, just replace those fake single quote marks with the real thing from your keyboard.2) None of the code samples that I tried above worked on the first query parameter in the query string.  Even the code samples that say they have this fixed still doesn&#039;t work. (I was getting my Query string from the Server variable.  Those who use a full URL might have different results).   I believe this is the case because all these code samples look for a &#039;&amp;&#039; symbol to separate query terms.  Obviously the first query term will never start with a &amp; symbol.</description> <content:encoded><![CDATA[<p>I have two warnings for readers stumble across this article:</p><p>1) Many of the code examples above gave syntax errors when I copied and pasted the code.  The syntax errors are caused by this webpage printing a single quotation mark as some other type of symbol that looks similar to a quote mark but is actually not.   To solve this, just replace those fake single quote marks with the real thing from your keyboard.</p><p>2) None of the code samples that I tried above worked on the first query parameter in the query string.  Even the code samples that say they have this fixed still doesn&#8217;t work. (I was getting my Query string from the Server variable.  Those who use a full URL might have different results).   I believe this is the case because all these code samples look for a &#8216;&amp;&#8217; symbol to separate query terms.  Obviously the first query term will never start with a &amp; symbol.</p> ]]></content:encoded> </item> <item><title>By: Chintan Shah</title><link>http://davidwalsh.name/php-remove-variable#comment-31421</link> <dc:creator>Chintan Shah</dc:creator> <pubDate>Mon, 02 Apr 2012 13:39:04 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-31421</guid> <description>Above issue is solved by following,
return preg_replace(&#039;/&#039;.$key.&#039;=[^&amp;]+?(&amp;)(.*)/i&#039;, &#039;$2&#039;, $url);But,
It&#039;s not working for removing last param from url or string, can anyone help for this !!!!</description> <content:encoded><![CDATA[<p>Above issue is solved by following,<br
/> return preg_replace(&#8216;/&#8217;.$key.&#8217;=[^&amp;]+?(&amp;)(.*)/i&#8217;, &#8216;$2&#8242;, $url);</p><p>But,<br
/> It&#8217;s not working for removing last param from url or string, can anyone help for this !!!!</p> ]]></content:encoded> </item> <item><title>By: Chintan Shah</title><link>http://davidwalsh.name/php-remove-variable#comment-31419</link> <dc:creator>Chintan Shah</dc:creator> <pubDate>Mon, 02 Apr 2012 13:10:17 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-31419</guid> <description>Did you get any solution for this ?</description> <content:encoded><![CDATA[<p>Did you get any solution for this ?</p> ]]></content:encoded> </item> <item><title>By: Chintan Shah</title><link>http://davidwalsh.name/php-remove-variable#comment-31417</link> <dc:creator>Chintan Shah</dc:creator> <pubDate>Mon, 02 Apr 2012 12:56:58 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-31417</guid> <description>what will be regex, if i want to remove any key from querystring [only] like,
tab=basic&amp;action=update&amp;tid=57969
want to delete key like, tab so the result will be ,
action=update&amp;tid=57969</description> <content:encoded><![CDATA[<p>what will be regex, if i want to remove any key from querystring [only] like,<br
/> tab=basic&amp;action=update&amp;tid=57969<br
/> want to delete key like, tab so the result will be ,<br
/> action=update&amp;tid=57969</p> ]]></content:encoded> </item> <item><title>By: Krrish</title><link>http://davidwalsh.name/php-remove-variable#comment-26870</link> <dc:creator>Krrish</dc:creator> <pubDate>Mon, 12 Sep 2011 11:07:31 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-26870</guid> <description>RegEx are Tough to understand... But they solve our problems in short...
I Use array in such Tasks.</description> <content:encoded><![CDATA[<p>RegEx are Tough to understand&#8230; But they solve our problems in short&#8230;<br
/> I Use array in such Tasks.</p> ]]></content:encoded> </item> <item><title>By: Tony</title><link>http://davidwalsh.name/php-remove-variable#comment-26239</link> <dc:creator>Tony</dc:creator> <pubDate>Tue, 26 Jul 2011 15:40:49 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-26239</guid> <description>I took the regex and expanded it.  PHP allows array references in the querystring vars such as http://www.example.com/?a[]=1&amp;a[0]=3&amp;a[5][7][89][fdds][ddd]=44Also, this function allows the removal of multiple vars.&lt;code&gt;
echo htmlentities(getRedirectURL(&quot;http://www.example.com/?a[]=1&amp;a[0]=3&amp;a[5][7][89][fdds][ddd]=44&quot;,&quot;a&quot;));
echo htmlentities(getRedirectURL(&quot;http://www.example.com/?a=1&amp;a=2&amp;b=3&amp;c=4&quot;,array(&quot;a&quot;,&quot;c&quot;)));
function getRedirectURL($url,$keysToRemove) {
if (!is_array($keysToRemove))
$keysToRemove = array($keysToRemove);
foreach ($keysToRemove as $key)
$url = preg_replace(&#039;/(?:&amp;&#124;(\\?&#124;\\G))&#039; . urlencode($key) . &#039;(?:\\[[^]]*\\])*=[^&amp;]*(?(1)&amp;&#124;)?/i&#039;, &quot;$1&quot;, $url);
if (substr($url,-1) == &#039;?&#039;)
$url = substr($url,0,-1);
return $url;
}
&lt;/code&gt;</description> <content:encoded><![CDATA[<p>I took the regex and expanded it.  PHP allows array references in the querystring vars such as <a
href="http://www.example.com/?a=1&#038;a0=3&#038;a5789fddsddd=44" rel="nofollow">http://www.example.com/?a=1&#038;a0=3&#038;a5789fddsddd=44</a></p><p>Also, this function allows the removal of multiple vars.</p><p><code><br
/> echo htmlentities(getRedirectURL("http://www.example.com/?a[]=1&amp;a[0]=3&amp;a[5][7][89][fdds][ddd]=44","a"));<br
/> echo htmlentities(getRedirectURL("http://www.example.com/?a=1&amp;a=2&amp;b=3&amp;c=4",array("a","c")));<br
/> function getRedirectURL($url,$keysToRemove) {<br
/> if (!is_array($keysToRemove))<br
/> $keysToRemove = array($keysToRemove);</p><p> foreach ($keysToRemove as $key)<br
/> $url = preg_replace('/(?:&amp;|(\\?|\\G))' . urlencode($key) . '(?:\\[[^]]*\\])*=[^&amp;]*(?(1)&amp;|)?/i', "$1", $url);</p><p> if (substr($url,-1) == '?')<br
/> $url = substr($url,0,-1);</p><p> return $url;<br
/> }<br
/> </code></p> ]]></content:encoded> </item> <item><title>By: Adrian Callaghan</title><link>http://davidwalsh.name/php-remove-variable#comment-23477</link> <dc:creator>Adrian Callaghan</dc:creator> <pubDate>Wed, 13 Apr 2011 09:58:57 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-23477</guid> <description>thanks!! lots of cool ways.I always like a regular expression but an alternative would be to use the ? as a delimiter and explode the uri into an array and retrieve the first result i.eecho reset(explode(&#039;?&#039;,$_SERVER[&#039;REQUEST_URI&#039;]));</description> <content:encoded><![CDATA[<p>thanks!! lots of cool ways.</p><p>I always like a regular expression but an alternative would be to use the ? as a delimiter and explode the uri into an array and retrieve the first result i.e</p><p>echo reset(explode(&#8216;?&#8217;,$_SERVER['REQUEST_URI']));</p> ]]></content:encoded> </item> <item><title>By: Charlie</title><link>http://davidwalsh.name/php-remove-variable#comment-18463</link> <dc:creator>Charlie</dc:creator> <pubDate>Mon, 28 Jun 2010 19:17:25 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-18463</guid> <description>I had an array of checkbox values being passed in the querystring, and I don&#039;t think these functions work for removing it.I found it easier to just directly define the $_SERVER[&#039;QUERY_STRING&#039;] by concatenating the $_GET[] variables I wanted to pass, and leaving out the ones I didn&#039;t (the checkbox array)</description> <content:encoded><![CDATA[<p>I had an array of checkbox values being passed in the querystring, and I don&#8217;t think these functions work for removing it.</p><p>I found it easier to just directly define the $_SERVER['QUERY_STRING'] by concatenating the $_GET[] variables I wanted to pass, and leaving out the ones I didn&#8217;t (the checkbox array)</p> ]]></content:encoded> </item> <item><title>By: Charlie</title><link>http://davidwalsh.name/php-remove-variable#comment-18462</link> <dc:creator>Charlie</dc:creator> <pubDate>Mon, 28 Jun 2010 19:16:54 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=4626#comment-18462</guid> <description>I had an array of checkbox values being passed in the querystring, and I don&#039;t think these functions work for removing it.I found it easier to just directly define the $_SERVER[&#039;QUERY_STRING&#039;] by concatenating the $_GET[] variables I wanted to pass, and leaving out the ones I didn&#039;t (the checkbox array)</description> <content:encoded><![CDATA[<p>I had an array of checkbox values being passed in the querystring, and I don&#8217;t think these functions work for removing it.</p><p>I found it easier to just directly define the $_SERVER['QUERY_STRING'] by concatenating the $_GET[] variables I wanted to pass, and leaving out the ones I didn&#8217;t (the checkbox array)</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 2/7 queries in 0.007 seconds using disk: basic
Object Caching 805/805 objects using disk: basic

Served from: davidwalsh.name @ 2012-05-23 16:44:26 -->
