Created
September 20, 2013 14:52
-
-
Save gingermusketeer/6638728 to your computer and use it in GitHub Desktop.
Convert json to php code
This file contains 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
function jsonToPhp(json, isNewPhpArrayStyle) { | |
var phpOpenArray = '['; | |
var phpCloseArray = ']'; | |
if(isNewPhpArrayStyle !== false) { | |
isNewPhpArrayStyle = true; | |
} | |
if(!isNewPhpArrayStyle) { | |
phpOpenArray = 'array('; | |
phpCloseArray = ')'; | |
} | |
return json.replace(/:/g, '=>').replace(/\{\s*\}/g, "new stdClass()").replace(/{/g, phpOpenArray).replace(/}/g, phpCloseArray); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment