PHP code example of rayanlevert / dotenv

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

    

rayanlevert / dotenv example snippets


$oDotenv = new \RayanLevert\Dotenv\Dotenv('/file/to/.dotenv');

$oDotenv->load();

NAME=1 => $_ENV['NAME'] = 1
NAME=23.34 => $_ENV['NAME'] = 23.34 (float values will be casted only with a dot .)
NAME=true => $_ENV['NAME'] = true
NAME=false => $_ENV['NAME'] = false
NAME=string value => $_ENV['NAME'] = 'string value'

    NAME="This is a variable
    with
    multiple
    lines"

    NESTED=VALUE
    NAME=${NESTED}
    NAME2=${NESTED}/path

    $_ENV['NESTED'] = 'VALUE'
    $_ENV['NAME'] = 'VALUE'
    $_ENV['NAME2'] = 'VALUE/path'

$oDotenv->