My site has lot of javascript, our frontend designer embedded settings code as json format, in js files . I need to this settings json value, from php server . and there are some dynamic changes. I coverted this settings json value into php array .. there are lot of them . so I written a function to convert into php code format
I have written a function toPhp
, which is posted in http://jsfiddle.net/2HKMU/
I tried to convert one js file settings into php code .. which works ..
var config_topfive = {
"type":"topfive",
"options":{
"ascending":false, "percentage":true, "limits":[25,5]
}
};
console.log( toPhp( config_topfive ) );
which prints
array(
"type" => "topfive",
"options" => array(
"ascending" => false,
"percentage" => true,
"limits" => array(25,5)
)
)
I would like to know, I miss anything on this conversion .. how could I improve this function more better ..
I know json_decode
, but I would like to keep this setting json value in js file ,which made by designer
in to php config file .. eg : config_topfive.php
. I will copy paste console print of this function console.log( toPhp( config_topfive ) )
into php file
so final my php code in config_topfive.php
look like
<?php
return array(
"type" => "topfive",
"options" => array(
"ascending" => false,
"percentage" => true,
"limits" => array(25,5)
)
);