View difference between Paste ID: mzf6J0YT and kzv5hkhC
SHOW: | | - or go back to the newest paste.
1-
public function dolar(){
1+
	public function getCurrencyConversion($currency = 'USD'){
2
3
		$content = file_get_contents("http://br.financas.yahoo.com/q?s={$currency}BRL=X");
4-
		$dolar = file_get_contents('http://br.financas.yahoo.com/q?s=USDBRL=X');
4+
		preg_match('/<span id=\"yfs_p20_'. strtolower($currency) .'brl=x\">(.*)<\/span>/', $content, $matches, PREG_OFFSET_CAPTURE);
5-
		$variacao_dolar = preg_match('/<span id=\"yfs_p20_usdbrl=x\">(.*)<\/span>/', $dolar, $matches, PREG_OFFSET_CAPTURE);
5+
		preg_match('/<span id=\"yfs_b00_'. strtolower($currency) .'brl=x\">(.*)<\/span>/', $content, $matches2, PREG_OFFSET_CAPTURE);
6-
		$dolarCompra = preg_match('/<span id=\"yfs_b00_usdbrl=x\">(.*)<\/span>/', $dolar, $matches2, PREG_OFFSET_CAPTURE);
6+
		preg_match('/<span id=\"yfs_a00_'. strtolower($currency) .'brl=x\">(.*)<\/span>/', $content, $matches3, PREG_OFFSET_CAPTURE);
7-
		$dolarVenda = preg_match('/<span id=\"yfs_a00_usdbrl=x\">(.*)<\/span>/', $dolar, $matches3, PREG_OFFSET_CAPTURE);
7+
		$variation = substr($matches[0][0], 29, 29);
8
		$buyPrice = substr($matches2[0][0], 28, 9);
9-
		$dolarCompra = substr($matches2[0][0], 28, 9);
9+
		$sellPrice = substr($matches3[0][0], 28, 9);
10
		$currencyVariation = preg_replace('/\)/', '', $variation);
11-
		$dolarVenda = substr($matches3[0][0], 28, 9);
11+
12-
		$variacao_dolar = substr($matches[0][0], 29, 29);
12+
13-
		$variacao = preg_replace('/\)/', '', $variacao_dolar);
13+
		echo <<<CURRENCY
14
15-
		$path = './';
15+
		<td><strong>{$currency}</strong></td>
16-
		echo <<<DOLAR
16+
		<td>$buyPrice</td>
17
		<td>$sellPrice</td>
18-
		<td><strong>DOLAR</strong></td>
18+
		<td class="green"><strong>$currencyVariation</strong></td>
19-
		<td>$dolarCompra</td>
19+
CURRENCY;
20-
		<td>$dolarVenda</td>
20+
21-
		<td class="green"><strong>$variacao</strong></td>
21+
22-
DOLAR;
22+