PHP append string with return

I have a function in PHP that takes the JSON output and returns it. What I’m trying to do is return that StdClass Object with some strings around it. Specifically, I need to wrap the object with this ‘JSON_CALLBACK()’.

I can echo ‘JSON_CALLBACK(‘ before returning the JSON but won’t be able to echo the remaining ‘)’ after. How can i append the missing ‘)’ after returning the JSON?

Here’s my code:

    public function showOutput() {

    try {
        $oauth = new OAuth($conskey,$conssec);
        $oauth->fetch($api_base . '/uItems');
        $json = json_decode($oauth->getLastResponse());
        return ($json);

    }
    catch(OAuthException $E) {
        return($E);
    }

    echo "JSON_CALLBACK(";
    return($json);
    echo ")"; //wont do anything since return is already called so how can i append this with return?

}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s