PHP code example of initphp / dotenv
1. Go to this page and download the library: Download initphp/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/ */
initphp / dotenv example snippets
composer
use \InitPHP\DotENV\DotENV;
DotENV::create('/home/www/.env');
DotENV::get('TRUE_VALE'); // true
DotENV::get('FALSE_VALUE'); // false
DotENV::get('SITE_URL'); // "http://lvh.me"
DotENV::get('PAGE_URL'); // "http://lvh.me/page"
DotENV::get('EMPTY_VALUE'); // ""
DotENV::get('NULL_VALUE'); // NULL
DotENV::get('NUMERIC_VALUE'); // 13
DotENV::get('PI_NUMBER'); // 3.14
DotENV::get('NOT_FOUND', 'hi'); // "hi"
return [
'SITE_URL' => 'http://lvh.me',
'PAGE_URL' => '${SITE_URL}/page',
'TRUE_VALE' => true,
'EMPTY_VALUE' => '',
'FALSE_VALUE' => false,
'NULL_VALUE' => null,
'NUMERIC_VALUE' => 13
];
use \InitPHP\DotENV\DotENV;
DotENV::create('/home/www/.env.php');
DotENV::get('TRUE_VALE'); // true
DotENV::get('FALSE_VALUE'); // false
DotENV::get('SITE_URL'); // "http://lvh.me"
DotENV::get('EMPTY_VALUE'); // ""
DotENV::get('NULL_VALUE'); // NULL
DotENV::get('NUMERIC_VALUE'); // 13
DotENV::get('NOT_FOUND', 'hi'); // "hi"
public function create(string $path, bool $debug = true): void;
public function get(string $name, mixed $default = null): mixed;
public function env(string $name, mixed $default = null): mixed;
# Comment Line
SITE_URL = http://lvh.me
PAGE_URL = ${SITE_URL}/page
; Comment Line
TRUE_VALE = true
EMPTY_VALUE = empty
FALSE_VALUE = false
NULL_VALUE = null
NUMERIC_VALUE = 13
PI_NUMBER = 3.14