razxc/dotenv

Parser for env-files with bash syntax compatibility and zero-dependencies


Keywords
parser, shell, environment, bash
License
MIT

Documentation

dotenv.php

The PHP library provides pure dot-env parser with bash syntax support and zero-dependencies. Required PHP 7.3 or higher.

Alternatives: symfony/dotenv vlucas/phpdotenv,


Feature

  • "export" notation
  • default values
  • multiline values
  • variable resolving

Installation

composer require razxc/dotenv

Example

$array = DotenvParser::fromFile('path/to/.env', $_ENV);

foreach ($array as $name => $value) {
    putenv("$name=$value");
}

foreach ($array as $name => $value) {
    print $name . ' => ' . getenv($name) . PHP_EOL;
}

TODO

  • command resolving