Download the PHP package prinx/dotenv without Composer
On this page you can find all versions of the php package prinx/dotenv. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package dotenv
Short Description Make easy access to the environment variables in your application
License MIT
Homepage https://github.com/prinx/dotenv
Informations about the package dotenv
PHP Dotenv
[](https://github.com/prinx/dotenv/actions/workflows/tests.yml)Get easily access to environment variables.
Installation
Open a command prompt into your project root folder and run:
Usage
Quick start
Writing a .env file
The .env file format will be:
For example:
As standard, the variable name is capital letter with underscores to separate words.
Comments
You can write comments in your .env file by preceding the comment by a hash (#
).
Example:
Types of values
By default, env variable will be retrieved as string, except booleans, and null.
String
You can use quotes to surround strings.
Boolean
The values true
, "true"
or 'true'
, will be got as the boolean true
.
The values false
, "false"
or 'false'
will be got as the boolean false
.
Same as:
Null
The values null
, "null"
or 'null'
, will be got as null
.
Referring to another variable
You can refer to the value of another variable in your .env file by putting the name of the variable you are referring to variable inside ${}:
Loading a specific .env file
By default, the package automatically look for the .env file in the project root folder. But you can load the env file from anywhere by using the loadenv
function:
Using the Dotenv instance
You can also get or set a variable using the Dotenv class instance:
The Dotenv instance can be accessed by calling the dotenv()
function:
Getting a variable
Getting all variables
Adding a variable to the current loaded environment
Writing a variable to the .env file
Create your own Dotenv instance
You can create your own Dotenv instance just by using the Dotenv
class:
Contributing
- Give a star to the repo :relaxed:
- Fork the repo.
- Correct a bug, add a new feature.
- Write tests.
- Create a pull request.
License
MIT