Skip to content

Instantly share code, notes, and snippets.

@elton182
Last active September 18, 2017 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elton182/dc34184a41b93d49cd02810d2817d030 to your computer and use it in GitHub Desktop.
Save elton182/dc34184a41b93d49cd02810d2817d030 to your computer and use it in GitHub Desktop.
Função para usar um arquivo como arquivo de ambiente (environment)
<?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