1. Go to this page and download the library: Download digimax/dot-env-editor 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/ */
digimax / dot-env-editor example snippets
use Digimax\DotEnvEditor\DotEnvEditor;
$envPath = __DIR__ . '/.env';
$editor = new DotEnvEditor(
$envPath, // the path to the.env file
true, // whether to keep a backup of the .env file before writing
);
// or using the static method
$editor = DotEnvEditor::load($envPath, true);
// set backup directory
$editor->setBackupDir(__DIR__ . '/backups');
// Get all variables
var_dump($editor->all());
// Get a specific variable
echo $editor->get('AUTHOR_NAME');
// Set a variable
$editor->set('AUTHOR_NAME', 'Raziul Islam');
// set multiple variables
$editor->set([
'AUTHOR_URL' => 'https://raziul.dev',
'AUTHOR_COUNTRY' => 'Bangladesh',
]);
// Remove a variable
$editor->remove('AUTHOR_URL');
// write back to the file
$editor->write();