[英]meaning of the following php code?
Guys I have been using the following code quite often but haven't properly understood the exact semantics of the functions.伙计们,我经常使用以下代码,但还没有正确理解函数的确切语义。 Especially for the last two str_replace functions.
特别是对于最后两个 str_replace 函数。 Can anybody explain me whats exactly happening here(in a little detail)?
谁能解释一下这里到底发生了什么(稍微详细一点)?
$this_file = str_replace('\\', '/', __FILE__);
$doc_root = $_SERVER['DOCUMENT_ROOT'];
$web_root = str_replace(array($doc_root, 'application/config.php'), '', $doc_root);
$srv_root = str_replace('application/config.php', '', $doc_root);
\
with forward slashes /
(the variable is not used after that).\
替换为正斜杠/
(之后不使用该变量)。application/config.php
from the document root string and store it in $web_root
(seems like useless code to me).application/config.php
并将其存储在$web_root
中(对我来说似乎是无用的代码)。application/config.php
from the document root string and store it in $srv_root
(again, seems like useless code, because a document root should be a directory, not a file).application/config.php
并将其存储在$srv_root
中(同样,这似乎是无用的代码,因为文档根应该是一个目录,而不是一个文件)。 Conclusion: It seems like this code could be translated into the following, and that none of these "calculations" are actually necessary:结论:似乎这段代码可以翻译成以下内容,并且这些“计算”实际上都不是必需的:
$doc_root = $_SERVER['DOCUMENT_ROOT'];
$web_root = '';
$srv_root = $doc_root;
Or even shorter:甚至更短:
$doc_root = $srv_root = $_SERVER['DOCUMENT_ROOT'];
$web_root = '';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.