Skip to content

Instantly share code, notes, and snippets.

@clytras
Forked from ArnaudLigny/PhpArrayToYaml.php
Created February 19, 2021 10:18
Show Gist options
  • Save clytras/87c633a1465064eb993c666f16db71c7 to your computer and use it in GitHub Desktop.
Save clytras/87c633a1465064eb993c666f16db71c7 to your computer and use it in GitHub Desktop.
Convert PHP array to YAML
{
"require": {
"symfony/yaml": "^3.2"
}
}
#!/usr/local/bin/php
<?php
if (php_sapi_name() !== 'cli') {
return;
}
date_default_timezone_set('Europe/Paris');
require_once 'vendor/autoload.php';
use Symfony\Component\Yaml\Yaml;
try {
$array = include('array.php');
$yaml = Yaml::dump($array);
file_put_contents('array.yml', $yaml);
echo "done!\n";
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment