[英]Need Assistance Interpreting PHP File
I have a new project that has a bit of code at the beginning of every page. 我有一个新项目,在每个页面的开头都有一些代码。 I am in need of some clarification on what this series of statements do.
我需要澄清这一系列声明的作用。 Here is the opening call:
这是开幕电话:
<?php
session_start();
$levels = 1;
include("../Connections/main.php");
include("../queries.php");
I understand all of it except how $levels = 1;
除了
$levels = 1;
之外,我了解所有内容$levels = 1;
relates to include("../queries.php");
与
include("../queries.php");
When I look at include("../queries.php");
当我看
include("../queries.php");
I see that it begins with the following statement: 我看到它始于以下语句:
<?php
switch($levels) {
case 1:
$dir = "../";
break;
case 2:
$dir = "../../";
break;
case 3:
$dir = "../../../";
break;
case 4:
$dir = "../../../../";
break;
case 5:
$dir = "../../../../../";
break;
}
function db_info($table,$where,$value,$info,$dir) {
//the functions just continue from there
This is the portion that I don't follow. 这是我不关注的部分。 I understand that there is a switch statement that offers several cases for
$dir
based upon the value of $levels
which was defined in the first bit of code. 我知道有一个switch语句根据
$levels
的值(在代码的第一位中定义)提供了$dir
的几种情况。 But how do these different outputs for the $dir
value translate? 但是
$dir
值的这些不同输出如何转换? Is this something you've seen or used before? 这是您以前见过或使用过的东西吗? What does the
../
stand for? ../
代表什么? Thanks. 谢谢。
../
refers to the parent directory of the current directory. ../
指当前目录的父目录。
../../
refers to the parent of the parent. ../../
指父母的父母。 etc. 等等
This is a ../
always refers to parent directory
, the more ../
the more parents you get. 这是一个
../
始终指向parent directory
, ../
您获得的parent directory
越多。 With enough you can get to the root of the file system (though you're better off just using /
). 有了足够的资源,您可以进入文件系统的根目录(尽管最好只使用
/
)。 This isn't exactly the best way to accomplish this. 这并不是完成此操作的最佳方法。
$dir = str_repeat( '../', $level );
Would be more obvious and it would be more extensible. 将会更加明显,并且会更加可扩展。 A better option still would be to have some config file which simply did something like:
更好的选择仍然是拥有一些简单的配置文件,例如:
// obviously this would be a better constant name.
define( 'PATH_TO_STUFF', dirname( __FILE__ ) ); // use __DIR__ on PHP 5.>=3
Bonus info: 奖金信息:
./
= current directory ./
=当前目录 ../
= parent directory ../
=父目录 ./../../
= grandparent of current directory ./../../
=当前目录的祖父母 ./../../foo/../
The parent directory of the folder foo
in the grandparent directory (ie. the grandparent directory). ./../../foo/../
祖父母目录(即祖父母目录)中的foo
文件夹的父目录。 (I am your father's, brother's, nephew's, cousin's former roommate) /
= file system root directory. /
=文件系统根目录。 The ../
means previous/parent directory. ../
表示先前/父目录。 So if $level == 1
, then $dir
will equal ../
. 因此,如果
$level == 1
,则$dir
将等于../
。
Something else must use dir to construct a path. 其他必须使用dir来构造路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.