• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Load a .env file with PHP

phpenvironment-variables


PHP Snippet 1:

USER_NAME='jfBiswajit'

PHP Snippet 2:

<?php

require_once realpath(__DIR__ . '/vendor/autoload.php');

// Looing for .env at the root directory
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

// Retrive env variable
$userName = $_ENV['USER_NAME'];

echo $userName; //jfBiswajit

Related Snippets

Redis Command To Sort Keys

Transpose and flatten two-dimensional indexed array where rows may not be of equal length

PHP: PDO + CSV export not downloading (headers issue?)

PHP: How to raise number to (tiny) fractional exponent?

Zig-zag scan an N x N array

Move a child array to parent array and change parent/child name

How do I pass the dynamic output of a php variable or php function to a CSS variable?

"There is no active transaction" when refreshing database in Laravel 8.0 test

Custom add to cart button URL for specific product in WooCommerce?

Pass a select with mysqli_fetch_row to a table

Laravel update hasMany relationship using saveMany

How to validate Envato Purchase Code in PHP

Detect emoticons in string

How to separate letters and digits from a string in php

Check If array is null or not in php

About Contact Privacy policy Terms and conditions