Read Data from YAML File using PHP

test.yaml

parameters:
  host: localhost
  port: 8080
  user: root

symfony/yaml library

  1. Add symfony/yaml library to composer.json file:
"require": {
    "symfony/yaml": "^5.0"
}
  1. Install library from the command line:
composer install
  1. Read data from YAML file:
<?php

use Symfony\Component\Yaml\Yaml;

require_once __DIR__ . '/vendor/autoload.php';

$data = Yaml::parseFile('test.yaml');

print_r($data);

Leave a Comment

Cancel reply

Your email address will not be published.