Created
January 26, 2015 14:35
-
-
Save ethaizone/aebf5e4d19cddb729b0a to your computer and use it in GitHub Desktop.
Lazy method but work - Helper for get baseUrl and basePath for website/webapp development
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 | |
if ( ! function_exists('basePath')) | |
{ | |
/** | |
* Get the path to the base of the install. | |
* | |
* @param string $path | |
* @return string | |
*/ | |
function basePath($path = '') | |
{ | |
$baseData = $_SERVER['SCRIPT_FILENAME']; | |
$posIndex = strpos( $baseData, '/'.basename($baseData)); | |
$base = substr( $baseData, 0, $posIndex); | |
$base = $path ? $base.'/'.$path : $base; | |
return $base; | |
} | |
} | |
if (! function_exists('baseUrl')) | |
{ | |
/** | |
* Get base path of url | |
* | |
* @param string $path | |
* @return string | |
*/ | |
function baseUrl($path = '') | |
{ | |
$baseData = $_SERVER['PHP_SELF']; | |
$posIndex = strpos( $baseData, '/'.basename($baseData)); | |
$base = substr( $baseData, 0, $posIndex); | |
$base = $path ? $base.'/'.$path : $base; | |
return $base; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment