PHP code example of nathanlesage / envedit
1. Go to this page and download the library: Download nathanlesage/envedit 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/ */
nathanlesage / envedit example snippets
use NathanLeSage\EnvEdit;
...
$editor = new EnvEdit('/path/to/your/.env');
// Read and parse the file
$editor->read();
// Retrieve the value of a specific variable.
// Of course, you should normally do this via env('APP_ENVIRONMENT')
// or similar.
$value = $editor->getValue('APP_ENVIRONMENT');
// Change one or more variables
$editor->setVars(
['APP_ENVIRONMENT' => 'production',
'REDIS_HOST' => '123.321.12.32']
);
// Write your changes to file
$editor->write();
// You could also retrieve the file's contents without writing them.
// This is useful for backup purposes or letting the user control what
// will be altered.
$editor->getFile();