PHP code example of ez-php / dotenv

1. Go to this page and download the library: Download ez-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/ */

    

ez-php / dotenv example snippets


use EzPhp\Env\Dotenv;

// Load .env from the project root (immutable — never overwrites existing env vars)
Dotenv::createImmutable(__DIR__)->load();

// Silently skip if the file doesn't exist (useful in production)
Dotenv::createImmutable(__DIR__)->safeLoad();

// Custom filename
Dotenv::createImmutable(__DIR__, '.env.testing')->load();

use EzPhp\Env\Parser;

$vars = (new Parser())->parse(file_get_contents('.env'));
// ['APP_NAME' => 'My App', 'APP_ENV' => 'production', ...]
bash
composer