Skip to content

Instantly share code, notes, and snippets.

@ashecret
Forked from hatch2/gist:3681758
Created November 3, 2016 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashecret/1250381d27fdc94466db971cf7bb903a to your computer and use it in GitHub Desktop.
Save ashecret/1250381d27fdc94466db971cf7bb903a 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