Do you need convert #JSON data to valid #PHP code without pain? I’ve got a short script for that! My simple solution used var_export() function. This function generates almost valid, well formatted PHP code from usual JSON data. Invalidity of code can be fix with one regular expression, which replace stdClass::__set_state/ with (object).
Take a closer look at example data. I have here currency.json - PHP code should look something like this:
It’s can be done in only four lines of PHP code:
If you need call some function (like gettext) above the variable, just add more regular expression: