PHP code example of oohology / dotenvwriter

1. Go to this page and download the library: Download oohology/dotenvwriter 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/ */

    

oohology / dotenvwriter example snippets


$writer = (new DotEnvWriter('.env.example'))
	->setOutputPath('.env');
// ...
$writer->save();

$writer = (new DotEnvWriter('.env.example'));
// ...
$writer->save('.env');

$writer = (new DotEnvWriter('.env'))
	->load('.env.example');
// ...
$writer->save();

// source: API_KEY=""
$writer->set('API_KEY', '1234', 'four-digit code');
// result: API_KEY=1234 # four-digit code

// source: API_KEY= # four-digit code
$writer->set('API_KEY', '1234', '');
// result: API_KEY=1234

// source: export API_KEY=""
$writer->set('API_KEY', '1234');
// result: export API_KEY=1234

// source: export API_KEY=""
$writer->set('API_KEY', '1234', null, false);
// result: API_KEY=1234
$writer->set('API_KEY', '1234', null, true);
// result: export API_KEY=1234

$writer->set('REGISTRATION_OPENED', true);
// result: REGISTRATION_OPENED=1


$writer->set('REGISTRATION_OPENED', false);
// result: REGISTRATION_OPENED=

$writer->castBooleans();

$writer->set('REGISTRATION_OPENED', true);
// result: REGISTRATION_OPENED=true


$writer->set('REGISTRATION_OPENED', false);
// result: REGISTRATION_OPENED=false

[
    'line' => 'export ENV="dev" # dev or live?',
    'export' => 'export',
    'key' => 'ENV',
    'value' => 'dev',
    'comment' => 'dev or live?'
];