<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:refactormycode.com,2007:users354</id>
  <link type="application/atom+xml" href="http://refactormycode.com/users/354" rel="self"/>
  <title>sgrezzeria</title>
  <updated>Thu Feb 07 20:46:31 +0000 2008</updated>
  <entry>
    <id>tag:refactormycode.com,2007:Refactor2170</id>
    <published>2008-02-07T20:46:31+00:00</published>
    <title>[PHP] On Removing Parameters from an URL</title>
    <content type="html">&lt;p&gt;Your code have some errors, but if I undestood right...&lt;/p&gt;

&lt;pre&gt;$ref = 'url.php?t=4&amp;amp;p=5&amp;amp;sid=ddf175fd02216cbe9fab9a4b528d7185&amp;amp;hilite=2c23tra#link';
$params = array('sid','t','p','hilite');

function cleanQueryString($ref, $params = NULL){
	$newparams = array();
	preg_match_all('|([^?&amp;amp;#=]+)=([^?&amp;amp;#=]+)(#{0,}[^?&amp;amp;#=]*)|', $ref, $out, PREG_SET_ORDER);
	
	foreach($out as $elem)
		if(!in_array($elem[1], $params))
			$newparams[] = &amp;quot;{$elem[1]}={$elem[2]}&amp;quot;;  
	return implode('&amp;amp;',$newparams) . $out[count($out)-1][3];	
}

echo cleanQueryString($ref, $params);
&lt;/pre&gt;</content>
    <author>
      <name>sgrezzeria</name>
      <email>dabduster@gmail.com</email>
    </author>
    <link type="text/html" href="http://refactormycode.com/codes/228-removing-parameters-from-an-url/refactors/2170" rel="alternate"/>
  </entry>
</feed>
