Skip to content

Instantly share code, notes, and snippets.

@magnum
Created December 16, 2022 15:01
Show Gist options
  • Save magnum/4d7ae490ec91b6b5bdacd9b135e190c3 to your computer and use it in GitHub Desktop.
Save magnum/4d7ae490ec91b6b5bdacd9b135e190c3 to your computer and use it in GitHub Desktop.
dotenv support in php, eg. wordpress
<?php
try {
require_once 'vendor/autoload.php';
$dotenv = Dotenv\Dotenv::createUnsafeImmutable('./');
$dotenv->load();
} catch (Exception $e) {
echo(implode("<br>", array(
("Caught exception: ".$e->getMessage()."<br>"),
"please be sure to install .env support package with 'composer require vlucas/phpdotenv'",
"and that a .env is present"
)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment