note 3453 deleted from function.parse-url by jimw
| From: | jimw@php.net | Date: | Fri, 21 Dec 2001 00:38:32 +0000 |
| Subject: | note 3453 deleted from function.parse-url by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-23653@lists.php.net to get a copy of this message | ||
Chances are, if you're using parse_url(), you're missing the point of PHP and one of its
coolest features--automatic parsing of variables and assignment of values. I'm sure there is
some esoteric need for parse_url(), but not if you're just trying to pass data from one page to
another.
If your URL is http://foo.com/?var1=foo&var2=bletch and you
want to print those values within your script, all you need is this:
<?
echo "var1 = $var1<br>",
"var2 = $var2<p>";
?>
This will print:
var1 = foo
var2 = bletch
You can also, for special cases, use the PATH_INFO environment variable. If you want to pass in
information without the ugly ?key=value& assignments, you can use PATH_INFO on a URL like
[http://foo.com/file.php/555/867-5309?name=Jenny] to do something like this:
<?
$argv = split("/", $PATH_INFO);
while (list($key,$val) = each($argv) ) {
printf("%s : %s<br>", $key, $val);
}
printf("%s's phone number is (%s) %s.<p>",
$name, $argv[1], $argv[2]);
?>
Thus passing this script a url like [http://domain.com/file.php/555/867-5309?name=jenny] will print:
"jenny's phone number is (555) 867-5309". But if you can't think of a reason why
you'd want to use PATH_INFO, don't sweat it--most people don't need it and likely
never will--it's just nice to have in your arsenal for "special occassions."
Hope this helps.