PHPackages                             initphp/dotenv - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. initphp/dotenv

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

initphp/dotenv
==============

DotENV Library/Package

2.0.1(2y ago)112911MITPHPPHP &gt;=5.6

Since Mar 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/InitPHP/DotENV)[ Packagist](https://packagist.org/packages/initphp/dotenv)[ RSS](/packages/initphp-dotenv/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)DependenciesVersions (4)Used By (1)

InitPHP DotENV
==============

[](#initphp-dotenv)

Loads environment variables from `.env` or `.env.php` file.

[![Latest Stable Version](https://camo.githubusercontent.com/f53a2fd01f284cb9c48776c891271e41ea5101d7bc335d23ac8873700d29c482/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f646f74656e762f76)](https://packagist.org/packages/initphp/dotenv) [![Total Downloads](https://camo.githubusercontent.com/cbe494d0693c07e2751a99fc87088f919b65577662fd5541382dc851c687479e/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f646f74656e762f646f776e6c6f616473)](https://packagist.org/packages/initphp/dotenv) [![Latest Unstable Version](https://camo.githubusercontent.com/b1c05db579535bdc1e2b81ee81c5818d04ab0bbb5292c18e25e4e8ffe19d2c81/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f646f74656e762f762f756e737461626c65)](https://packagist.org/packages/initphp/dotenv) [![License](https://camo.githubusercontent.com/1e5631eb1e75c3f6dfcf2fb99f9b924db0d8d0409ad7ecb089a53246eb29d9c9/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f646f74656e762f6c6963656e7365)](https://packagist.org/packages/initphp/dotenv) [![PHP Version Require](https://camo.githubusercontent.com/f4696c381f63fe55c26c4943939997f68aef7def16c4ded91ab447f834a680db/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f646f74656e762f726571756972652f706870)](https://packagist.org/packages/initphp/dotenv)

Requirements
------------

[](#requirements)

- PHP 5.6 or higher

Installation
------------

[](#installation)

```
composer require initphp/dotenv
```

Usage
-----

[](#usage)

**Note :** Lines starting with any non-alphanumeric character are counted as comments and are not processed.

**Note :** Existing definitions in the `$_SERVER` or `$_ENV` globals are not processed.

### `.env` File

[](#env-file)

***Note that .env files are externally accessible. To prevent access with `.htaccess` or better yet keep your `.env` file in a directory that cannot be accessed externally.***

`/home/www/.env` :

```
# 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

```

`any.php` :

```
require_once "vendor/autoload.php";
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"
```

### `.env.php`

[](#envphp)

`/home/www/.env.php` :

```
