2013-02-23 196 views
-1

我必須改變RON tu EUR ang的價格,並在我的操作中獲得0

我使用的代碼:

include('./panou/simple_html_dom.php'); 
    function euro() { 
     $dom= file_get_html("http://www.cursvalutar.ro/");; 
     foreach ($dom->find('tr') as $node) { 
     if (is_a($node->children(1), 'simple_html_dom_node')) { 
      if ($node->children(1)->plaintext == "Euro") { 
      $plain = explode(',', $node->children(2)->plaintext);   
     if(!isset($plain[0])!== false) { 
         echo("Nu are"); 
        } 
      elseif(stripos($plain[0], $plain[0])!== false{ 
         "4.30" 
        } 
      } 
     } 
    } 
    $plain[0]*=$koyos; echo "$plain[0]";} 

$plain[0] = 4.3780$koyos = 545.66腳本的結果是0

+4

這真的是一個PHP代碼?如果是這樣,那麼if(...){「4.30」}'後面的推理是什麼?如果某件事情是真的,創建和丟棄字符串文字有什麼意義? ...不用介意丟失的右括號。 – 2013-02-23 08:33:29

+0

@Jan Dvorak:因爲「爲什麼不呢?」 – zerkms 2013-02-23 08:34:29

+0

包含語法錯誤(在Cthulhu編輯後可見)。關閉太過本地化? – 2013-02-23 08:35:31

回答

0

問題與代碼: $ koyos變量沒有歐元()函數定義。 將它傳遞給函數。 如果您想打印一個數組的元素,你應該這樣做:

 echo $plain[0] 
    echo "{$plain[0]}" // this two prints what you want 

這不是好辦法:

 echo "$plain[0]"  // the result of this might be "Array[0]" 

不過還好這個替換代碼:

function getEuroRon(){ 
      if (!$file = fopen('http://download.finance.yahoo.com/d/quotes.csv?s=EURRON=X&f=sl1d1t1ba&e=.csv','r')){ 
        die('resource can not be read'); 
      } 
      $data = fgetcsv($file); 
      fclose($file); 
      return $data[1]; 
    } 
    $euroron = getEuroRon(); 
    /* 
    //... somewhere in code: 
    $koyos = 545.66; 

    //i dont recommend to use global variables but you might need this: 
    function euro(){ 
      global $koyos,$euroron; 
      print $euroron * $koyos; 
    } 
    */ 
    //This should be better instead the previous: 
    function euro($koyos){ 
      global $euroron; 
      print $euroron * $koyos; 
    } 
    euro(545.66); 

你可以調用euro()函數,你需要打印結果... 應該有mutch更好的方式,但我不知道你的代碼的其他細節,並嘗試t o以與編碼相同的方式解決您的問題。

或者你可以使用一點點更好的解決方案: http://pastebin.com/HMp8SR2j

+0

試試這個@NiTrO – Kovge 2013-02-23 09:11:13

相關問題