Created
November 18, 2015 02:15
-
-
Save nflint/a7f2d16747bb128cf791 to your computer and use it in GitHub Desktop.
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
function psuedo_json_to_array($psuedo_json) | |
{ | |
//Check if this is suedo json. If not exit with notice. | |
if (strpos($psuedo_json,"<=") !== false && strpos($psuedo_json,"=>") !== false){ | |
$psuedo_json = str_replace("<=", "{", $psuedo_json); | |
$json_string = str_replace("=>", "}", $psuedo_json); | |
$json_errors = json_validate($json_string); | |
//This will take care of the rest if the inside does not have the correct formatting. | |
// | |
if($json_errors == false){ | |
exit("This is not correct JSON"); | |
}else{ | |
$array = json_decode($json_string,true); | |
return $array; | |
} | |
}else{ | |
exit("This string does not appear to be valid Psuedo JSON!"); | |
} | |
} | |
function json_validate($string) { | |
if (is_string($string)) { | |
@json_decode($string); | |
return (json_last_error() === JSON_ERROR_NONE); | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment