nazares/phpdotenv

Loads environment variables from .env file to `getenv()`, `$_ENV` and `$_SERVER`

v1.0.3 2023-06-24 19:30 UTC

This package is auto-updated.

Last update: 2024-12-24 22:56:40 UTC


README

Loads environment variables from .env file to getenv(), $_ENV and $_SERVER

Installation

composer require nazares/phpdotenv

Usage

.env file

DB_HOST =localhost
DB_NAME = test
DB_PASSWORD= secret
$dotenv = new \nazares\phpdotenv\Dotenv($path);
$dotenv->load();

echo getenv('DB_HOST'); // localhost
echo $_ENV['DB_NAME']; // test
echo $_SERVER['DB_PASSWORD']; // secret

or

(new \nazares\phpdotenv\Dotenv($path))->load();

echo getenv('DB_HOST'); // localhost
echo $_ENV['DB_NAME']; // test
echo $_SERVER['DB_PASSWORD']; // secret