note 56653 deleted from function.file by bjori

From: Date: Wed, 22 Mar 2006 13:47:10 +0000
Subject: note 56653 deleted from function.file by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106249@lists.php.net to get a copy of this message
Note Submitter: rohan (dot) mk1 (at) gmail (dot) com ---- This code will help you if you want to pass the URL to the script by GET and the URL includes "&", so the address bar looks like "http://www.example.com/script.php ?url=http://www.example.com/script2.php ?var1=value1&var2=value2&var3=value3" and the effect of echo $_GET['url']; is "url=http://www.example.com/script2.php?var1=value1" because everything after the "&" is stored in other variables, so the $_GET array contains the foollowing key/value pairs: $_GET ( [url] => url=http://www.example.com/script2.php?var1=value1 [var2] => value2 [var3] => value3 ) This will give the file() function the proper url: <?php $url = $_GET['url']; $array = array(); $count = 1; //removes the $url from $array, also a counter for custom variables //if you want to pass multiple variables to the script, they must be before $url in $_GET if (array_key_exists('customvar1', $_GET)) { $count += 1; //increases the counter } while (list($key, $val) = each($_GET)) { if ($count) //if ($count <> 0), else stops decreasing the counter and starts defining $array { $count -= 1; } else { $array[] = $key . "=" . $val; } } $urlending = "&" . implode("&", $array); //the proper ending of the address $url .= $urlending; ?> the counter may be removed, but $array will also contain $url, so be careful and use only: $url = implode("&", $array); If you can't use the following code for any reason, pass to the script the address with additional "anything=" after every "&" and then use $url .= implode ('&', $_GET); NOTE: The 'anythings' must be different after each '&'. Hope thet helps someone

« previous php.notes (#106249) next »