5 Replies Latest reply on Aug 7, 2009 10:47 AM by kglad

    PHP & Flash - String to Integer conversion problem

    Wasim Khamlichi



      In my flash application I have a currency converter. This converter calls a PHP script, which accesses Google for an updated conversion rate, then returns the rate back to Flash. Now this whole procedure works absolutely fine on my MAMP server at home, and on many other clients servers. My current client is on 110mb.com hosting, and for some reason, the currency rate returned by the PHP script, is not an integer and fails to convert to an integer using the Number() function. This is baffling me, I don't understand the problem. Here is the script;


      The flash application uses LoadVars and the currency() function is called. This then echo's "rate=1.1243" or whatever the currency rate is. Then flash receives the variable "rate" and does what it needs to do. Now....flash can trace(rate) absolutely fine, but when I trace(Number(rate)), I get NaN


      On my home server and many other servers, it will convert to a number, but it doesn't work using 110mb.com server.


      Appreciate your help



      loadCurrency.load(_root.DOMAIN + "admin/flashFunctions.php?action=currency&convertTo=" + currency);
      loadCurrency.onLoad = function(success:Boolean):Void {
           if (success) {
                      trace(rate); // e.g 1.0283 <- correct
                      trace(Number(rate)); // NaN



      function curl_file_get_contents($url) {
              $ch = curl_init();
              $ret = curl_exec($ch);
      function exchangeRate( $amount, $currency, $exchangeIn ) {
           $googleQuery = $amount . ' ' . $currency . ' in ' . $exchangeIn;
           $googleQuery = urlEncode( $googleQuery );
           $askGoogle = curl_file_get_contents( 'http://www.google.com/search?q=' . $googleQuery );
           $askGoogle = strip_tags( $askGoogle );
           $matches = array();
           preg_match( '/= (([0-9]|\.|,|\ )*)/', $askGoogle, $matches );
           return $matches[1] ? $matches[1] : false;
      function currency() {
           echo "rate=" . number_format(exchangeRate( 1, 'USD', $_GET['convertTo']), 4);