PHP code example of srdorado / php-dotenv
1. Go to this page and download the library: Download srdorado/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/ */
srdorado / php-dotenv example snippets
use Srdorado\Env\DotEnv;
$absolutePathToEnvFile = __DIR__ . '/.env';
(new DotEnv($absolutePathToEnvFile))->load();
/**
* string(33) "mysql:host=localhost;dbname=test;"
*/
var_dump(getenv('DATABASE_DNS'));
/**
* Removes double and single quotes from the variable:
*
* string(4) "root"
*/
var_dump(getenv('DATABASE_USER'));
/**
* Processes booleans as such:
*
* bool(true)
*/
var_dump(getenv('MODULE_ENABLED'));
/**
* Process the numeric value:
*
* int(0)
*/
var_dump(getenv('NUMBER_LITERAL'));
/**
* Check for literal null values:
*
* NULL
*/
var_dump(getenv('NULL_VALUE'));
composer