Is it acceptable to use a switch
as a way of supporting multiple file formats, or is it bad practice?
Like so (untested):
<?php
// Load file
switch ($data_format) {
case 'xml':
$openfile = simplexml_load_file($filename . '.xml');
break;
case 'json':
$openfile = json_decode(file_get_contents($filename . '.json'));
break;
}
// Do stuff
// Save file
switch ($data_format) {
case 'xml':
$openfile->asXML($filename . '.xml');
break;
case 'json':
file_put_contents($filename . '.json', json_encode($openfile, JSON_PRETTY_PRINT));
break;
}
?>