Last active
September 18, 2017 01:12
-
-
Save elton182/dc34184a41b93d49cd02810d2817d030 to your computer and use it in GitHub Desktop.
Função para usar um arquivo como arquivo de ambiente (environment)
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 | |
/** | |
* retorna uma variavel de ambiente do arquivo .env | |
* | |
* @param [type] $var | |
* @return string | |
*/ | |
function env($var) | |
{ | |
$file = dirname(__DIR__) . '/../.env'; | |
$env = ''; | |
if ($file = fopen($file, "r")) { | |
while(!feof($file)) { | |
$line = fgets($file); | |
$envLine = explode('=',$line); | |
if( !is_null($envLine) ){ | |
if ($envLine[0] == $var){ | |
$env = $envLine[1]; | |
} | |
} | |
} | |
fclose($file); | |
} | |
return preg_replace( "/\r|\n/", "", $env );; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment