<?php
// read_env.php

// Path to Laravel .env file
$envPath = __DIR__ . '/./.env';  // adjust if needed

if (!file_exists($envPath)) {
    die(".env file not found at $envPath");
}

// Read lines
$lines = file($envPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

foreach ($lines as $line) {
    // Skip comments
    if (str_starts_with(trim($line), '#')) continue;

    // Split key=value
    list($name, $value) = array_map('trim', explode('=', $line, 2));

    // Remove quotes around value
    $value = trim($value, "\"'");

    // Set environment variable
    putenv("$name=$value");

    // Optionally set in $_ENV and $_SERVER
    $_ENV[$name] = $value;
    $_SERVER[$name] = $value;
}

// Example usage: access .env variables
$dbHost = getenv('DB_HOST');
$appName = getenv('APP_NAME');

echo "App Name: $appName\n";
echo "Database Host: $dbHost\n";
die;
?>