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 8291331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:05:35+00:00 2026-06-08T13:05:35+00:00

I have a PHP file that’s running a simple check for currency conversion. It

  • 0

I have a PHP file that’s running a simple check for currency conversion. It works perfectly when I run it through my browser but my goal is to build a cron. When I run the script via SSH:

php /path/to/file.php

I get the following:

PHP Warning:  json_encode(): Invalid UTF-8 sequence in argument in /path/to/file.php on line 36

Where line 36 is:

fwrite($fh, json_encode($conversions));

…where $conversions is a simple single-dimension array

Here’s the file:

$conversions = array();

$currencies = json_decode(file_get_contents("/path/to/currencies.json"), true);

foreach($currencies as $cur=>$data){


    //make string to be put in API
    $string = "1USD=?".$data['code'];
    //Call Google API
    $google_url = "http://www.google.com/ig/calculator?hl=en&q=".$string;

    $ch = curl_init();  
    // set URL and other appropriate options  
    curl_setopt($ch, CURLOPT_URL, $google_url);  
    curl_setopt($ch, CURLOPT_HEADER, 0);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     
    // grab URL and pass it to the browser    
    $result = curl_exec($ch);
    //Explode result to convert into an array
    $result = explode('"', $result);

    $converted_amount = explode(' ', $result[3]);
    $conversion = $converted_amount[0];
    //$conversion = $conversion * $amount;
    $conversions[$cur] = $conversion;
    if($conversion==0){ exit('0 Return Error'); }

    curl_close($ch);

}

$fh = fopen("/path/to/currency_conversions.json", 'w') or die("can't open file");
fwrite($fh, json_encode($conversions));
fclose($fh);
  • 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-08T13:05:38+00:00Added an answer on June 8, 2026 at 1:05 pm

    Well, I searched for you and I found the json_encode acceptes only UTF-8
    so here is the solution:

    for($i=0;$i<count($conversions);$i++)
        $conversions[$i] = utf8_encode($conversions[$i]);
    fwrite($fh, json_encode($conversions));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file that is only accessed through ajax. The ajax call
I have a PHP file that I would like to run once per day.
I have a php file that runs a simple jquery script: var text =
I have a PHP file that is needed to be run from the command
I have a php file that needs to be run on a cronjob and
I have a php file that can read the contents of other files perfectly
I have a PHP file that contains a large array (about 90KB). I'm considering
I have a PHP file that contains a lot of if and else statements
I have a php file that contains a form (which contains 2 input boxes
I have a PHP file that I need it to detect it's directory it's

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.