argenton 0 Denunciar post Postado Dezembro 12, 2011 Pode ser um simples, que apenas mostre a cotação e que não seja muito grande. Já testei muitos aí e nenhum funcionou, por ser antigo (2009, 2010). Alguém dá uma mãozinha? Obrigado Compartilhar este post Link para o post Compartilhar em outros sites
Henrique Barcelos 290 Denunciar post Postado Dezembro 12, 2011 Tenho um aqui que pego do portal da revista Exame: <?php $file = "http://portalexame.abril.com.br/static/aberto/lafisxml/indicadores.xml"; //$file = ROOT."includes/cotacoes.xml"; $xml = @simplexml_load_file($file); if($xml){ $items = $xml->Indicadores->Item; $cotations = '<div class="wrapper">'; $cotations .= '<ul id="main-cotations">'; foreach($items as $each){ $name = $each["nome"]; $osc = $each["oscilacao"]; $date = $each["dataNeg"]; $value = $each["valor"]; if(preg_match("/Dolar|Euro|Poupanca|SELIC|CDI|Ouro/i", $name)){ if(preg_match("/Dolar|Euro|Ouro/i", $name)){ $value = (float) $value; $value = "R$ ".number_format($value, 2, ",", "."); $osc = (float) $osc; if($osc > 0){ $class = "positive"; $osc = number_format($osc, 2, ",", "."); $osc = "▲".$osc."%"; } else if($osc < 0){ $class = "negative"; $osc = abs($osc); $osc = number_format($osc, 2, ",", "."); $osc = "▼".$osc."%"; } else { $osc = number_format($osc, 2, ",", "."); $class = "stable"; } if(preg_match("/Dolar/i", $name)){ $name = "Dólar (US$)"; } else if(preg_match("/Euro/i", $name)){ $name = "Euro (€)"; } else { $name = "Ouro (R$)"; } $cotations .= "\t\t\t\t<li class=\"cotation\"> <table class=\"cotation-values\"> <caption>{$name}</caption> <tbody> <tr><th>Valor:</th><td>{$value}</td></tr> <tr><th>Variação:</th><td class=\"{$class}\">{$osc}</td></tr> <tr><th>Data:</th><td>{$date}</td></tr> </tbody> </table> </li>\n"; } elseif(preg_match("/poupanca/i", $name)) { $name = "Poupança"; $osc = (float) $osc; if($osc > 0){ $class = "positive"; $osc = number_format($osc, 2, ",", "."); $osc = "▲".$osc."%"; } else if($osc < 0){ $class = "negative"; $osc = number_format($osc, 2, ",", "."); $osc = "▼".abs($osc)."%"; } else { $osc = number_format($osc, 2, ",", "."); $class = "null"; } $cotations .= "\t\t\t\t<li class=\"cotation\"> <table class=\"cotation-values\"> <caption>{$name}</caption> <tbody> <tr><th>Variação:</th><td class=\"{$class}\">{$osc}</td></tr> <tr><th>Data:</th><td>{$date}</td></tr> </tbody> </table> </li>"; } else { if(preg_match("/SELIC/i", $name)){ $name = "SELIC (Ano)"; } else { $name = "CDI (Ano)"; } $value = (float) $value; $value = number_format($value, 2, ",", ".")."%"; $cotations .= "\t\t\t\t<li class=\"cotation\"> <table class=\"cotation-values\"> <caption>{$name}</caption> <tbody> <tr><th>Valor:</th><td>{$value}</td></tr> <tr><th>Data:</th><td>{$date}</td></tr> </tbody> </table> </li>"; } } } $cotations .= '</ul>'; $cotations .= '<a href="javascript:void(0)" id="cotations-toggle">+ Mais</a>'; $cotations .= '</div>'; $cotations .= "<cite>Fonte: Portal Exame</cite>"; } else { $cotations = "<p class=\"no-data\">Indisponível no momento</p>"; } echo $cotations ?> Tem bem mais coisas que o Dólar aí, é só filtrar o que você deseja... Compartilhar este post Link para o post Compartilhar em outros sites
argenton 0 Denunciar post Postado Dezembro 12, 2011 Henrique, obrigado pela ajuda! Funcionou direitinho :D Compartilhar este post Link para o post Compartilhar em outros sites