Skip to content

Instantly share code, notes, and snippets.

@hatch2
Created September 9, 2012 01:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hatch2/3681758 to your computer and use it in GitHub Desktop.
Save hatch2/3681758 to your computer and use it in GitHub Desktop.
use json_encode & json_decode at old php
<?php
//JSON.php -> http://pear.php.net/package/Services_JSON/
require_once 'JSON.php';
if ( !function_exists('json_decode') ){
function json_decode($content, $assoc=false){
if ( $assoc ){
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
} else {
$json = new Services_JSON;
}
return $json->decode($content);
}
}
if ( !function_exists('json_encode') ){
function json_encode($content){
$json = new Services_JSON;
return $json->encodeUnsafe($content);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment