使用 PHP $_GET 修正超链接 URL 的语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13852424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Correct syntax for hyperlink URL with PHP $_GET
提问by maxgee
I am wondering how I would put information from my website in the URL on the first page of my site, and then on the next page, use $_GETto get the variables from the URL.
我想知道如何将我网站上的信息放在我网站第一页的 URL 中,然后在下一页上,用于$_GET从 URL 获取变量。
I was just wanting to put it in a link like <a href="mywebsite.com/page?name=$name"></a>So would it work if I did it like that, and if it would, how would I get it from the URL?
我只是想把它放在一个像<a href="mywebsite.com/page?name=$name"></a>这样的链接中如果我这样做会不会起作用,如果会的话,我将如何从 URL 中获取它?
回答by Charles
Example Link: http://example.com/page.php?name=Charles
示例链接: http://example.com/page.php?name=Charles
If you used $_GET["name"]it would return the value Charles
如果你使用$_GET["name"]它会返回值Charles
For more information on $_GET look at http://php.net/manual/en/reserved.variables.get.php
有关 $_GET 的更多信息,请查看http://php.net/manual/en/reserved.variables.get.php
回答by Sudhir Bastakoti
do
做
<a href="http://mywebsite.com/page?name=<?php echo $name; ?>"></a>
And in your page, you could get the name as:
在您的页面中,您可以将名称设为:
$name = $_GET['name'];
回答by kennypu
the $_GETis the variable. so in this case, to get the name, it would be:
的$_GET是变量。所以在这种情况下,要获得名称,它将是:
$_GET['name'];

