This repository contains small scripts as well as instructions to read .env files in several languages.
For using it in PHP first you have to have:
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";
?>