I want to be able to move my code and be able to discover a path in order to influence the value of certain variables. This will be placed on the page where the variables are initialized.
Here is what I came up with:
$path_array = explode('/', $_SERVER['SCRIPT_FILENAME']); $out = ""; // -3 represents the number of folders and files to go back to reach the wanted path for($i=0; $i < count($path_array) - 3; $i++){ $out .= $path_array[$i].'/'; }
Then, as an example, I can do the following:
$dyn_path_1 = $out . 'folder1/'; $dyn_path_2 = $out . 'folder2/something_else/'; $dyn_path_3 = $out . 'folder3/';
Are there any built-in functions that I could lose that would make this obsolete?
ps: this will allow us to have several working copies of the code without worrying about these variables whenever we check the code.
Edit # 1:
Variable file path: root / folderA / folderB / var.php
Inside var.php, I need to go back to the root, which is 2-3 steps depending on the method. I wonder if it is possible to do something like this:
echo some_function("../../file_I_know.php");
which could return: C: / root /
source share