Podría quedar de la siguiente manera
Código PHP:
Ver original<?php
curl_setopt($ch, CURLOPT_URL
, 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv'); /* No cerramos la conexion */
//curl_close($ch);
/* esto es innecesario */
//{
?>
Apple stock price: <?php echo $contents[1] ?>
<?php
/* esto es innecesario */
//}
?>
<?php
/* no volvemos a iniciar curl por que aun esta abierta la conexion */
//$ch = curl_init();
curl_setopt($ch, CURLOPT_URL
, 'http://download.finance.yahoo.com/d/quotes.csv?s=GOOG&f=sl1d1t1c1ohgv&e=.csv'); /* esto ya se establecio al iniciar curl */
//curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
/* esto es innecesario */
//{
?>
Google stock price: <?php echo $contents[1] ?>
<?php
/* esto es innecesario */
//}
?>
Y eliminando lo inecesario quedaria algo así:
Código PHP:
Ver original<?php
curl_setopt($ch, CURLOPT_URL
, 'http://download.finance.yahoo.com/d/quotes.csv?s=AAPL&f=sl1d1t1c1ohgv&e=.csv'); /* Guardamos el resultado en una variable*/
$Apple_stock_price=$contents[1];
curl_setopt($ch, CURLOPT_URL
, 'http://download.finance.yahoo.com/d/quotes.csv?s=GOOG&f=sl1d1t1c1ohgv&e=.csv'); /* Guardamos el resultado en una variable*/
$Google_stock_price=$contents[1];
/* Ahora que tenemos los resultados en variables podemos mostrarlo en pantalla o
o tambien hacer cualquier otra operacion con ellos como guardarlos en una BD */
echo ' Precio Apple: '.$Apple_stock_price;
echo ' Precio Google: '.$Google_stock_price;
?>