Show sourcecode
The following files exists in this folder. Click to view.
.gitattributes
.gitignore
classes/
comments.php
credentials.env
dbconnect.php
envparser.php
exercises/
exercises.php
filefinder.php
img/
incl/
index-no-include.php
index.php
myexercises.php
source.php
style/
viewsource.php
envparser.php
30 lines ASCII Windows (CRLF)
<?php
function parseEnvFile($filePath)
{
if (!file_exists($filePath)) {
// Optionally handle the case where the file does not exist
throw new Exception("The file at $filePath does not exist.");
}
$envArray = [];
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0) {
continue; // Skip comments
}
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value);
// Remove surrounding quotes from the value
$value = trim($value, "\"'");
$envArray[$name] = $value;
}
return $envArray;
}