Created
June 10, 2017 11:20
-
-
Save u01jmg3/5351da8e568032a158b045f287e402bc to your computer and use it in GitHub Desktop.
Generate an absolute or relative path based on the location of the current file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Absolute | |
$path = current(preg_split('@(?<=public)@', getcwd())); | |
require_once "{$path}\includes\config.inc.php"; | |
// Relative | |
$path = preg_split('/public/', getcwd()); | |
$path = explode(DIRECTORY_SEPARATOR, trim(end($path), DIRECTORY_SEPARATOR)); | |
require_once str_repeat('../', count($path)) . 'includes/config.inc.php'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment