Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6215139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:00:01+00:00 2026-05-24T07:00:01+00:00

I am trying to decode the Google Dictionary API JSON response with PHP, but

  • 0

I am trying to decode the Google Dictionary API JSON response with PHP, but I am running into an issue where I cannot seem to parse the response (json_decode returns NULL).

An example JSON response is located here (searching for the word “oracle”).

The JSON API requires that you submit a callback function, so I chose something really short (a), since it’s unnecessary to deal with.

Here is my code:

<?php
$query = 'oracle';
$file = file_get_contents('http://www.google.com/dictionary/json?callback=a&q='.$query.'&sl=en&tl=en&restrict=pr,de&client=te');
var_dump($file);
$json = json_decode($file);
var_dump($json);
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:00:02+00:00Added an answer on May 24, 2026 at 7:00 am

    Google returns the result in the form of a function call. If you want to get rid of that you can do:
    So you have to strip that part off:

    $file = substr($file, 2, -10);
    

    Furthermore all the hex characters cause a mess. I don’t know the best way of dealing with these (they should be converted to their character, but how to go about that easily requires thought). For testing purposes you can just strip them (to see that it then works).
    Try:

    $file = preg_replace("/\\\x[0-9a-f]{2}/", "", $file);
    

    So in the end you have:

    <?php
    $query = 'oracle';
    $file = file_get_contents('http://www.google.com/dictionary/json?callback=a&q='.$query.'&sl=en&tl=en&restrict=pr,de&client=te');
    // var_dump($file);
    $file = substr($file, 2, -10);
    $file = preg_replace("/\\\x[0-9a-f]{2}/", "", $file);
    echo $file;
    $json = json_decode($file);
    var_dump($json);
    ?>
    

    For converting the characters as needed, I suppose you could use preg_replace_callback, but I don’t like that function, specially when the data comes from a remote source. Simpler may be to simply have a static mapping, eg:

    $from = array("\x3d", "\x22", ...);
    $to = array("=", "\"", ...);
    $file = str_replace($from, $to, $file);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to decode JSON in php I sended using an ajax call
I'm trying to use the Google directions API to show directions on my mapview
Im trying to shorten a url using ggole api's.Here is my php code .It
I'm trying to decode some JSON and insert the values in MySQL. Here is
I have been trying to plot these on a scatter chart using google api.
I am trying to retrieve some data from the Google Maps API from a
Disclaimer: I am fairly new to using json. I am trying to use php
Trying to decode an invalid encoded utf-8 html page gives different results in python,
I'm trying to decode the result of the Python os.wait() function. This returns, according
I'm trying to decode a WBXML encoded SyncML message from a Nokia N95. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.