2013-02-23 200 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

相关问题