PHP Classes

File: src/Export.php

Recommend this page to a friend!
  Classes of Zacchaeus Bolaji   PHP Env Export   src/Export.php   Download  
File: src/Export.php
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: PHP Env Export
Export environment variables to a file
Author: By
Last change:
Date: 2 months ago
Size: 444 bytes
 

Contents

Class file image Download
<?php

function export_env($from='.env', $to='.env.example')
{
    if(!
file_exists($from)) {
        throw new \
Exception("File [$from] not found");
    }
   
$files = file($from);
   
$newFile = $to;
   
file_put_contents($newFile, '');
    foreach (
$files as $file) {
       
$key = explode("=", $file)[0];
        if (empty(
trim($key))) continue;
       
file_put_contents($newFile, "$key=" . PHP_EOL, FILE_APPEND);
    }
    return
true;
}