[Dotenv] improve documentation for dotenv component

This commit is contained in:
Simon / Yami
2025-05-28 11:01:39 +02:00
committed by Nicolas Grekas
parent 28347a8977
commit b0a2dffe11

View File

@@ -11,6 +11,15 @@ Getting Started
composer require symfony/dotenv
```
Usage
-----
> For an .env file with this format:
```env
YOUR_VARIABLE_NAME=my-string
```
```php
use Symfony\Component\Dotenv\Dotenv;
@@ -25,6 +34,12 @@ $dotenv->overload(__DIR__.'/.env');
// loads .env, .env.local, and .env.$APP_ENV.local or .env.$APP_ENV
$dotenv->loadEnv(__DIR__.'/.env');
// Usage with $_ENV
$envVariable = $_ENV['YOUR_VARIABLE_NAME'];
// Usage with $_SERVER
$envVariable = $_SERVER['YOUR_VARIABLE_NAME'];
```
Resources