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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:10:20+00:00 2026-05-31T16:10:20+00:00

I’m looking for some assistance with some code. I’m trying to put this to

  • 0

I’m looking for some assistance with some code. I’m trying to put this to bed as it’s driving me nuts. The Psuedo code for this would be to

  1. Download the rates from the Yahoo API and declare my base rate to my foreign exchange.
  2. Store an array of currencies to choose from to compare against the base currency.
  3. I then GET the chosen currency and register it in a SESSION to be used on other pages. (I’m unsure if this is correct?)
  4. I then calculate the Price of my product which is in GBP to the selected foreign currency.
  5. Output the converted price anywhere on the page.

My script takes GET values from the URL like so:

.com?c=EUR

My code is like so..

  1. First I get the rates from the Yahoo API:

    session_start();
    
    $from   = 'GBP';
    $to     = '$c';
    $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X';
    $handle = @fopen($url, 'r');
    
    if ($handle) {
      $result = fgets($handle, 4096);
      fclose($handle);
    }
    $allData = explode(',',$result); /* Get all the contents to an array */
    $PoundValue = $allData[1];
    
  2. Then I store an array of the currencies.

    $currency_array = array ('USD','EUR','RMB','JPY','AUD','CHF')
    
  3. Then I get the chosen currency.

     if(isset($_GET['c'])) {  
         $c = $_GET['c'];
    
        if(array($currency_array)) {
            $_SESSION['currency_array'] = $c;
        }
     }
    
  4. I then calculate the product price.

     $Total = $Price * $currency_array; 
    
     $outprice = number_format($Total, 2, '.', ',');
    
  5. Then I output on the page

     <?php echo .$outprice; ?>
    

So is all my coding logically in the right order?

Any help would be greatly appreciated.

Just as a side note. When I type in the URL ending in .php?c=EUR

I have put a dump in there and my output is

array
  0 => string '"GBP$C=X"' (length=9)
  1 => string '0.00' (length=4)
  2 => string '"N/A"' (length=5)
  3 => string '"N/A"

' (length=7)

Why is the $c value not being returned as the chosen currency?

Cheers,

Jonah

  • 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-31T16:10:21+00:00Added an answer on May 31, 2026 at 4:10 pm
    $to = '$c';
    

    should probably just be

    $to = $c;
    

    or

    $to = "$c"; // redundant "make a string of this string" version.
    

    Single quoted strings do not interpolate variable values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to loop through a bunch of documents I have to put
I have a jquery bug and I've been looking for hours now, I can't
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.