'PHP - Load data from file with format X=Y
I have a file without any format called .env.
All the values are stored like this: X=Y
My supervisor told me to load this data into my PHP script, I need the values as array. He said I can do it because the file is build like an ini file. But there are no sections.
I tried it like this:
$ini_array = parse_ini_file("../../.env"); // Output: false
$data = include("../../.env"); // Output: 1 -> prints the content of the file into the document
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:WVS0jXq4FBEOHEt2+K3AxyLCvTgq5L/dMhiFd5HZg7Q=
APP_DEBUG=true
APP_URL=http://api-konfigurator.local
JWT_SECRET=5PdNYddJuntDfbErQBg0vnUwwNCJiDy8hc1QMNAFaAWsdKJv2fe6m3ueLbYdYOk3
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=x
DB_USERNAME=y
DB_PASSWORD=z
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
