Skip to content

Instantly share code, notes, and snippets.

@ahmadrosid
Created December 20, 2019 16:22
Show Gist options
  • Select an option

  • Save ahmadrosid/84dc7bbc817f5058b2bf0a546cb4bce6 to your computer and use it in GitHub Desktop.

Select an option

Save ahmadrosid/84dc7bbc817f5058b2bf0a546cb4bce6 to your computer and use it in GitHub Desktop.
PHP super simple dotenv
function load_env()
{
	if ($fh = fopen('../.env', 'r')) {
	    while (!feof($fh)) {
	        $line = fgets($fh);
	        putenv($line);
	    }
	    fclose($fh);
	}
}

function env($key, $default = null)
{
	$value = getenv($key);
	if ($value === false) {
  		return $default;
	}
	return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment