Skip to content

Instantly share code, notes, and snippets.

@ArnaudLigny
Last active May 24, 2023 10:52
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save ArnaudLigny/fbe791e05b93951ffc1f6abda8ee88f0 to your computer and use it in GitHub Desktop.
Save ArnaudLigny/fbe791e05b93951ffc1f6abda8ee88f0 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";
}
@yassinechabli
Copy link

nice try. thank you

@RyanNutt
Copy link

RyanNutt commented Jun 4, 2022

Exactly what I was looking for. Thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment