How to extract parameters from a URL and storing each in a new variable using PHP
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3508450/how-to-grab-url-parameters-using-php">How to grab URL parameters using PHP?</a>  </p>
</blockquote>



<p>I was wondering how can I store each url parameter each in there own new variable when I don't know how deep the url parameters are?</p>

<p>Here is an example of a URL value.</p>

<p><a href="http://www.localhost.com/topics/index.php?cat=3&amp;sub1=sub-1&amp;sub2=sub-2&amp;sub3=sub-3&amp;sub4=sub-4" rel="nofollow">http://www.localhost.com/topics/index.php?cat=3&amp;sub1=sub-1&amp;sub2=sub-2&amp;sub3=sub-3&amp;sub4=sub-4</a></p>

<p>Here is my PHP script.</p>

<pre><code> $url = $_SERVER['QUERY_STRING'];
 $query = array();

 if(!empty($url)){
   foreach(explode('&amp;', $url) as $part){
   list($key, $value) = explode('=', $part, 2);
   $query[$key] = $value;
  }
 }
</code></pre>
