Last active
May 24, 2023 10:52
-
-
Save ArnaudLigny/fbe791e05b93951ffc1f6abda8ee88f0 to your computer and use it in GitHub Desktop.
Convert PHP array to YAML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"require": { | |
"symfony/yaml": "^3.2" | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; | |
} |
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
nice try. thank you