在 PHP 中,使用 YAML 时,是否可以使用 yaml 文件内的特定文档?
例如
--- #settings
Settings go here
...
--- #user
Users go here
...
是否可以仅将用户加载到 php 中,以便我只能使用该文档数据?
使用 Symfony YAML 组件或 Spyc
<?php
require_once 'vendor/autoload.php'; // Load the autoload from Symfony YAML Component
use Symfony\Component\Yaml\Yaml;
// YAML file path
$file = 'path/to/your/file.yaml';
// Load the entire YAML file
$data = Yaml::parseFile($file);
// Access the data for the 'user' section
$usersData = $data['user'];
// Now you can work with $usersData
// ...
?>