note 56653 added to function.file
| From: | dot) | Date: | Sun, 11 Sep 2005 13:59:41 +0000 |
| Subject: | note 56653 added to function.file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95009@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.file.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56653
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56653&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56653&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56653&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56653&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56653&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56653&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56653&report=yes
Search -- http://master.php.net/manage/user-notes.php