read-dotenv-files

This repository contains small scripts as well as instructions to read .env files in several languages.

View the Project on GitHub Baelfire18/read-dotenv-files

PHP Dotenv

For using it in PHP first you have to have:

  1. A PHP version installed.

  2. Installed the php-dotenv package. If you have composer installed you can do it just by running composer require vlucas/phpdotenv.

For a .env file like this:

<?php
  require("vendor/autoload.php");
  $dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);

  $dotenv -> load(".env");

  $DB_NAME = $_ENV['DB_NAME'];
  echo $DB_NAME . "\n";
?>