PHP implementation of the POSIX-compliant dotenv file format specification.
composer require xdg/dotenv
Loading environment variables from a set of dotenv files:
use Xdg\Dotenv\XdgDotenv;
$env = XdgDotenv::load([
__DIR__ . '/.env',
__DIR__ . '/.env.local',
]);
// $env is an associative array containing the loaded variables.
var_dump($env);
If you want to evaluate the dotenv files without loading them into the environment, use the following:
use Xdg\Dotenv\XdgDotenv;
$env = XdgDotenv::evaluate([
__DIR__ . '/.env',
__DIR__ . '/.env.local',
]);
// $env is an associative array containing the loaded variables.
var_dump($env);