见HTTP GET Variables
如果您的网址是
www.example.com/index.php?name=Joanna
这意味着$_GET["name"]
是 “乔安娜”。
所以在PHP中,你可以输出:
<?php echo "Hi ".$_GET["name"]."!"; ?>
,它会输出,在这种情况下:
嗨乔安娜!
您还可以检查该变量存在,并且不为空通过执行下列操作之一:
isset($_GET["name"]) //will return true even if $_GET==""
!empty($_GET["name"])
$_GET["name"]!=""
所以你可以在你的PHP输出更改为:
if(!empty($_GET["name"])){
$name = $_GET["name"];
} else {
$name = "guest";
}
echo "Hi, ".$name."!";
如果$_GET["name"]
为空,将输出“guest”。
较短以上的版本:
echo "Hi, ".(empty($_GET["name"]) ? "guest" : $_GET["name"])."!";
来源
2015-11-04 17:04:36
Ben
http://stackoverflow.com/questions/13852424/correct-syntax-for-hyperlink-url-with-php-get - HTTP:// PHP。 net/manual/en/reserved.variables.get.php - http://stackoverflow.com/questions/33497892/how-to-use-get-a-html-href-asd –
谢谢 - 正如所说,我不能' t找到正确的东西,因为我不知道它叫什么:) –
欢迎您和*欢迎使用Stack * –