Created
July 2, 2021 07:37
-
-
Save kdssoftware/5064473a8941fe92bad887eac14c6e22 to your computer and use it in GitHub Desktop.
loads .env file into $_ENV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class env | |
{ | |
//usage: | |
//env::$load() // loads .env file | |
//env::$load("dev") //loads dev.env file | |
//CAUTION! : at an empty line after the last variable entry. see example below | |
public static function load ($prefix="") { | |
$file = file($_SERVER['DOCUMENT_ROOT'].'/ici/'.$prefix.'.env'); | |
foreach ($file as $line_num => $line) { | |
$ar = explode('=',$line); | |
if(count($ar)==2) { | |
$_ENV[$ar[0]] = substr($ar[1], 0, -2); | |
} | |
} | |
} | |
} | |
//start .env example: | |
//foo=bar | |
//first=1 | |
// | |
//end .env example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks