php 什么是 $_SERVER['QUERY_STRING'] ?这个怎么运作?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18184211/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:07:12  来源:igfitidea点击:

what is $_SERVER['QUERY_STRING'] ? how it works?

php

提问by asdas

$Q = explode("/", $_SERVER["QUERY_STRING"]);

What can be the possible $Q's value?

什么是可能$Q的价值?

回答by jogesh_pi

for example you have a URL in browser like this

例如你在浏览器中有一个像这样的 URL

relation.php?variable1/variable2/variable3

and you want the get the value after the ?
then $_SERVER['QUERY_STRING']helps you to determine the part the string after the ?

并且您希望获取之后的值?
然后$_SERVER['QUERY_STRING']帮助您确定字符串之后的部分?

and according to your question

并根据你的问题

$Q = explode("/", $_SERVER["QUERY_STRING"]);

variable $Qis an array with the values like

变量$Q是一个数组,其值如下

Array
(
  [0] => variable1
  [1] => variable2
  [2] => variable3
)

take a look on the $_SERVERand explode()

看看$_SERVER爆炸()

回答by Rahul

If a page is accessed via any query string, $_SERVER['QUERY_STRING'] fetches that query string.

如果通过任何查询字符串访问页面,则 $_SERVER['QUERY_STRING'] 获取该查询字符串。

Example :

例子 :

<?php  
echo "The query string is: ".$_SERVER['QUERY_STRING'];  
?>  

If the above php code is saved with a filename of QUERY_STRING.php and if you add '?tutorial=php&section=super-globals' (i.e. QUERY_STRING.php?tutorial=php&section=super-globals);it will print this string in the page since you have asked the script to print $SERVER['QUERY_STRING'].

如果上面的 php 代码以 QUERY_STRING.php 的文件名保存,并且如果您添加 '?tutorial=php§ion=super-globals' (i.e. QUERY_STRING.php?tutorial=php&section=super-globals);,它将在页面中打印此字符串,因为您已要求脚本打印 $SERVER['QUERY_STRING' ]。

For more info goto :

欲了解更多信息,请转到:

http://php.net/manual/en/reserved.variables.server.php

http://php.net/manual/en/reserved.variables.server.php

回答by Nirmal Subedi

Explode : Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.

Explode :返回一个字符串数组,每个字符串都是字符串的子字符串,通过在字符串定界符形成的边界上将其拆分而形成。

array explode ( string $delimiter , string $string [, int $limit ] )

数组爆炸(字符串 $delimiter ,字符串 $string [, int $limit ] )

Run this Code to Understand :

运行此代码以了解:

/* A string that doesn't contain the delimiter will simply return a one-length array of the original string. */

$input1 = "hello";
$input2 = "hello,there";
var_dump( explode( ',', $input1 ) );
var_dump( explode( ',', $input2 ) );

The above example will output:

上面的例子将输出:

array(1)
(
    [0] => string(5) "hello"
)
array(2)
(
    [0] => string(5) "hello"
    [1] => string(5) "there"
)

And, In Your Case, Your Current Query String will be Splited into Array. And, Each / will be a array item.

并且,在您的情况下,您当前的查询字符串将被拆分为数组。而且,每个 / 将是一个数组项。

Like if explode( '/', 'foo/bar')

就像如果爆炸('/','foo/bar')

Array will contain Foo and Bar into seperate index.

Array 将包含 Foo 和 Bar 到单独的索引中。

For More : Explode : Explode Details from PHP.NET$_SERVER : $_Server Details from PHP.NET

更多信息:爆炸:来自 PHP.NET 的爆炸细节$_SERVER:来自 PHP.NET 的 $_Server 细节