diff --git a/src/read_env_file.php b/src/read_env_file.php index 6176ec8..400ef7e 100644 --- a/src/read_env_file.php +++ b/src/read_env_file.php @@ -49,11 +49,12 @@ function readEnvFile(string $path = __DIR__, string $env_file = '.env'): int // wirte only if env is not set yet, and write only the first time if (empty($_ENV[$var])) { if (!empty($quotes)) { - $block = true; // match greedy for first to last so we move any " if there are if (preg_match('/^"(.*[^\\\])"/U', $value, $matches)) { $value = $matches[1]; } else { + // this is a multi line + $block = true; // first " in string remove // add removed new line back because this is a multi line $value = ltrim($value, '"') . PHP_EOL; diff --git a/test/.env b/test/.env index cca580b..4c97044 100644 --- a/test/.env +++ b/test/.env @@ -2,6 +2,7 @@ SOMETHING=A OTHER="B IS B" Complex="A B \"D is F" +# COMMENT HAS_SPACE= "ABC"; FAILURE = ABC SIMPLEBOX= A B C