1. Go to this page and download the library: Download fkrzski/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/ */
fkrzski / dotenv example snippets
use Dotenv\Dotenv;
$dotenv = new Dotenv('.env');
$dotenv->start();
$dotenv = new Dotenv('path/to/file/myenvfile.env');
// Now you are using myenvfile.env from /path/to/file folder
$dotenv = new Dotenv('path/to/file/myenvfile.env', 'path/to/file/mysecondenvfile.env');
echo getenv('APP_NAME');
echo $_SERVER['APP_NAME'];
echo $_ENV['APP_NAME'];
// output: My App Name
$dotenv->start(['APP_NAME']);
echo getenv('APP_NAME');
echo getenv('API_KEY');
// Output:
// Second App Name
// ApiKey
$dotenv->start(['*']);
echo getenv('APP_NAME');
echo getenv('API_KEY');
// Output:
// Second App Name
// SecondApiKey