1. Go to this page and download the library: Download julienlinard/php-dotenv library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
julienlinard / php-dotenv example snippets
ulienLinard\Dotenv\Dotenv;
// Load the .env file from the root directory
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
// Access variables
echo $_ENV['DB_HOST'];
echo $_ENV['DB_NAME'];
use JulienLinard\Dotenv\Dotenv;
// Create an immutable instance (does not replace existing variables)
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
use JulienLinard\Dotenv\Dotenv;
$dotenv = Dotenv::createImmutable(__DIR__);
$dotenv->load();
// Validate that certain variables exist
$dotenv->
// Validate with default values
$dotenv->
// Get a variable with default value
$dbHost = Dotenv::get('DB_HOST', 'localhost');
use JulienLinard\Core\Application;
$app = Application::create(__DIR__);
// Load the .env file
$app->loadEnv();
// Variables are now available in $_ENV
$dbHost = $_ENV['DB_HOST'];
$dbName = $_ENV['DB_NAME'];