我又一次拾起碎片,发现了这个片段。它没有评论,我很难剖析它存在的原因。这是可爱的发现在requests.php
$host = $_SERVER['HTTP_HOST'];
$self = $_SERVER['PHP_SELF'];
$query = !empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
$url = !empty($query) ? "http://$host$self?$query" : "http://$host$self";有什么想法吗?
UPDATE I能够理解该URL被解析,但我不明白为什么(这应该是任何代码文档的精髓)。我不认为这需要投反对票。代码和问题都提供了,我留下了这个空白处,这样就不能指导答案了。对这样一个问题的无数回答表明,这并不是一件坏事。
发布于 2014-05-12 21:11:58
它试图解析当前正在执行的页面的URL。所以:
http://example.com/somepage.php?foo=bar
将是:
$host = 'example.com';
$self = '/somepage.php';
$query = 'foo=bar';发布于 2014-05-12 21:13:58
$host = $_SERVER['HTTP_HOST']; // returns the host of the site
$self = $_SERVER['PHP_SELF']; // returns the current page
/*
* a ternary condition asking if the URL has a query string,
* if so make $query equal to the string,
* if not make $query null
*/
$query = !empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
/*
* a ternary condition checking if $query is empty
* if it isn't, concatenate the three elements
* if it is only concatenate two of them
*/
$url = !empty($query) ? "http://$host$self?$query" : "http://$host$self";发布于 2014-05-12 21:11:44
如果您的页面位于http://www.test.com/test.php?x=y&1=2
$query = 'x=y&1=2‘
还有..。
$url = 'http://www.test.com/test.php?x=y&1=2‘
这可以用于在某些页面上显示特定内容--例如,如果存在查询,等等.
https://stackoverflow.com/questions/23618899
复制相似问题