Skip to content

Instantly share code, notes, and snippets.

@evaisse
Last active August 11, 2020 08:31
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 evaisse/00b1e376f33d52edebda8e39428d8b03 to your computer and use it in GitHub Desktop.
Save evaisse/00b1e376f33d52edebda8e39428d8b03 to your computer and use it in GitHub Desktop.
A simple dotenv (.env) file parsing function to avoid dependencies
<?php
function read_dotenv(string $filePath) {
$envs = parse_ini_file($filePath);
foreach ($envs as $k => $v) {
$k = strtoupper($k);
putenv("$k=$v");
$_ENV[$k] = $_SERVER[$k] = $v;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment