PHP code example of natanael-oliveira / dot-env
1. Go to this page and download the library: Download natanael-oliveira/dot-env library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
natanael-oliveira / dot-env example snippets
tanaelOliveira\DotEnv\Environment;
// Create an instance of the Environment class
$env = new Environment();
// Set the environment variables
$env->set('DB_HOST', 'host');
$env->set('DB_USER', 'user');
$env->set('DB_PASS', 'password');
$env->set('DB_PREFIX', 'db_prefix_');
// Get environment variables
$dbHost = $env->get('DB_HOST');
$dbUser = $env->get('DB_USER', 'default_user');
$dbPass = $env->get('DB_PASS');
// Remove environment variables
$env->remove('DB_PREFIX');
// Use environment variables in your application
echo "DB Host: $dbHost<br>";
echo "DB User: $dbUser<br>";
echo "DB Password: $dbPass<br>";