Mawhorter.net Forums

Home of the facelift image replacement forums

You are not logged in.

Announcement

It looks like recaptcha is easily thwarted either by cheap labor or some other means, because I am still getting tons of spam signups.

I'm closing registrations again, if you would like to register, please email me at cory.mawhorter@ephective.com and use the subject line "Forum Registration". Give me your name and all the standard stuff in that email.

I will just have to do manual registrations until I have more time to spend on this problem.

-Cory, 2010-03-15

#1 2008-08-07 07:45:09

Fippe
Smurf
Registered: 2008-08-07
Posts: 2

Fatal error: Call to undefined function json_decode()

Thanks for bringing FLIR to us. Flash is not needed anymore.

Though I am having hard time installing it on our web server. The generate.php-file uses the function "json_decode" which don't seems to be supported on PHP versionens older than 5.2.0. (using 5.1.x)

Are there any other function that we could use instead of json_decode?

Many thanks in advance.

Cheers!

--
Fatal error: Call to undefined function json_decode() in XXXX/generate.php on line XX

Line XX: $FStyle = preg_match('#^\{("[\w]+":"[^"]*",?)*\}$#i', $_GET['fstyle'])?json_decode($_GET['fstyle'], true):array();
--

Offline

 

#2 2008-08-07 08:36:28

Fippe
Smurf
Registered: 2008-08-07
Posts: 2

Re: Fatal error: Call to undefined function json_decode()

I did actually solve this problem.

People who don't uses PHP 5.2.0+ might be interested in this solution.

1. Download JSON.php and put in i same folder as FLIR generate.php. --> http://mike.teczno.com/JSON.tar.gz
2. Add these lines at the bottom of JSON.php, but before "?>"

// Future-friendly json_encode
// Cred: http://abeautifulsite.net/notebook/71
if( !function_exists('json_encode') ) {
    function json_encode($data) {
        $json = new Services_JSON();
        return( $json->encode($data) );
    }
}

// Future-friendly json_decode
if( !function_exists('json_decode') ) {
    function json_decode($data, $bool) {
        if ($bool) {
            $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        } else {
            $json = new Services_JSON();
        }
        return( $json->decode($data) );
    }
}

4. Import the new JSON library by adding this line at the top of generate.php:
include("JSON.php");



//F

Offline

 

#3 2008-08-07 11:12:23

cory
Administrator
From: Detroit
Registered: 2008-08-05
Posts: 929
Website

Re: Fatal error: Call to undefined function json_decode()

Yaaa... that's what I was going to recommend.  Thanks for reporting it here and posting a solution.  I'm making legacy PHP support a priority for the next release.


Check out Facelift v2.0 beta 3.  The best version yet.

Offline

 

#4 2008-09-16 14:49:16

cory
Administrator
From: Detroit
Registered: 2008-08-05
Posts: 929
Website

Re: Fatal error: Call to undefined function json_decode()

For any searchers finding this page, if you don't want to use the above library you could use this function:

Code:

if(!function_exists('json_decode')) {
    // very plain json_decode
    function json_decode($str, $ignore=true) {
        $str = trim($str);
        if(!preg_match('#^\{(("[\w]+":"[^"]*",?)*)\}$#i', $str, $m)) return array();
        $data = explode('","', substr($m[1], 1, -1));
        $ret = array();
        for($i=0; $i<count($data);$i++) {
            list($k,$v) = explode(':', $data[$i], 2);
            $ret[substr($k, 0, -1)] = substr($v, 1);
        }
        
        return $ret;
    }
}

It will only convert single dimensional json objects but that is all I ever need to do anyway.  Otherwise, you could use the above library.  This code comes from Facelift Image Replacement's inc-flir.php file.


Check out Facelift v2.0 beta 3.  The best version yet.

Offline

 

#5 2009-01-12 17:14:59

paul.irish
Steve
Registered: 2008-10-29
Posts: 8

Re: Fatal error: Call to undefined function json_decode()

Wow i'm happy i found this thread. :)

Cory, we tried your json_decode but didnt have any luck with it.

This was our final implementation. very similar to Fippe's but using a require inside. That way it plays nicely in both 5.1 and 5.2.

Code:

// PHP Compat stuff
if (!function_exists('json_encode')) {
    require_once 'JSON/JSON.php';
    function json_encode($arg)
    {
            global $services_json;
            if (!isset($services_json)) {
                    $services_json = new Services_JSON();
            }
            return $services_json->encode($arg);
    }
} 

if( !function_exists('json_decode') ) {
    require_once 'JSON/JSON.php';
    function json_decode($data, $bool) {
        if ($bool) {
            $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        } else {
            $json = new Services_JSON();
        }
        return( $json->decode($data) );
    }
}

Offline

 

#6 2009-01-19 23:37:51

cory
Administrator
From: Detroit
Registered: 2008-08-05
Posts: 929
Website

Re: Fatal error: Call to undefined function json_decode()

Yeah... that function only works in limited circumstances.  Mainly... single dimensional arrays with pretty vanilla keys and values.  You could modify the regex to allow for more characters and to check for escaped quotes but I haven't because there was no need for it with FLIR.


Check out Facelift v2.0 beta 3.  The best version yet.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2008 PunBB