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

  • SEARCH
  • Home
  • 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 8365027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:33:57+00:00 2026-06-09T12:33:57+00:00

I’m trying to do a curl request to the google currency converter URL. This

  • 0

I’m trying to do a curl request to the google currency converter URL. This part works, and I get back the JSON data however the data appears to be in the wrong encoding. If I try to convert encoding or adjust the values in any way it doesn’t work and my json_decode returns NULL.

Do I need to specify encoding or is it related to the keys not having quotes around them?

Here’s some code to get a result from them:

    $url = "https://www.google.com/ig/calculator?hl=en&q=" . $amount . $from . "=?" . $to;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    $return = curl_exec($ch);
    curl_close($ch);

    var_dump($return);

The result is usually something around this {lhs: "9Â 808.90 U.S. dollars",rhs: "7Â 986.40287 Euros",error: "",icc: true}

I converted the encoding to ISO-8859-1 and it had proper spaces, but it still won’t json_decode properly…

Any suggestions?

  • 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-06-09T12:33:58+00:00Added an answer on June 9, 2026 at 12:33 pm

    I never get that weird strings.

    test.php

    <?php
        $amount = '10$';
        $to = 'EUR';
        $url = "https://www.google.com/ig/calculator?hl=en&q=" . $amount . $from . "=?" . $to;
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)");
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);
        $return = curl_exec($ch);
        curl_close($ch);
    
        // dump the output
        var_dump($return);
    
        /*
        string(59) "{lhs: "10 US$",rhs: "8.14199642 Euros",error: "",icc: true}"
        */
    
        // quote the unquoted data from Google
        $forJSON = str_replace(array('lhs', 'rhs', 'error', 'icc'), array('"lhs"', '"rhs"', '"error"', '"icc"'), $return);
    
        // decode the JSON string and turn it into an array
        $toArray = json_decode($forJSON, true);
    
        // dump the array
        print_r($toArray);
    
        /* 
        Array
        (
            [lhs] => 9 808.90 U.S. dollars
            [rhs] => 7 986.40287 Euros
            [error] => 
            [icc] => 1
        )
        */
    ?>
    

    things you should try:

    • make sure you save your file as ANSI – you will get weird values otherwise
    • if above sollution doesn’t work, try remaking the file, there must be an encoding somewhere.
    • or maybe you copied 9,808.90 from some program that doesn’t actually use , and it’s another character there
    • also you should know that Google responds with unquoted data, that is not JSON valid, try to escape like I did and you should be able to decode
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.