Created
April 12, 2013 10:19
-
-
Save shinofara/5371060 to your computer and use it in GitHub Desktop.
需要は無いかもしれないが、ini形式をyaml形式に変換する処理を書いてみた。 ref: http://qiita.com/items/12cc1bf4b6e1c4ec5703
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
<?php | |
$ini = parse_ini_file($_SERVER['argv'][1],true); | |
foreach($ini as $section => $conf){ | |
echo $section,":\n"; | |
//sction内ループ | |
foreach($conf as $key => $val){ | |
if(is_array($val)){ | |
echo " ",$key,":\n"; | |
foreach($val as $num => $file){ | |
echo " - ",$file,"\n"; | |
} | |
} | |
else { | |
echo " ",$key,": ",$val,"\n"; | |
} | |
} | |
} | |
?> |
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
php trance.php test.ini > test.yml |
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
test: | |
name: value | |
age: 12 | |
test: | |
- test1 | |
- test2 | |
test2: | |
name: value | |
age: 12 | |
test: | |
- test1 | |
- test2 |
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
[test] | |
name=value | |
age=12 | |
test[]=test1 | |
test[]=test2 | |
[test2] | |
name=value | |
age=12 | |
test[]=test1 | |
test[]=test2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment