• 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

Convert every two values of an associative array into key-value pairs

Fatal error: Uncaught TypeError: count(): Argument #1 ($var) must be of type Countable|array, null given in

Show rotation of tweets using current day of month

Convert string to lowercase AND then convert it to its original form in PHP, is it possible?

Hide specific products from unlogged users based in product category in WooCommerce

Edit product hook WooCommerce

Store multiple fields in JSON column (Nova CMS)

PDOException SQLSTATE[HY000] [2002] No such file or directory

str_replace or preg_replace random number from string

javascript html popup window

I want to display default profile image if user do not have profile image

Laravel print last executed SQL query with Query log

I'm trying to use curl with php but getting this error:Could not resolve host: Bearer

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

How to get the survey List from surveygizmo API in the Postman?(Trial Version)

About Contact Privacy policy Terms and conditions