Mailinglisten-Archive |
Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------B13C9F8E8AF0168D1D18E3FE
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Sebastian Bergmann schrieb:
> =
> Marian Steinbach wrote:
> > Weist Du zuf=E4llig, wo _genau_ man diie Kurse bekommt? Ich habe unte=
r obiger
> > URL nichts gefunden.
> =
> Ich habe da mal vor langer Zeit was f=FCr geschrieben. Hoffe, das
> funktioniert noch.
Hallo!
Das ist ja fein. Ich glaube, ich habe einen Fehler gefunden. Die erste
Funktion und die Klasse haben den selben Namen. Damit hat es bei mir nich=
t
funktioniert, stattdessen gabe es eine Fehlermeldung (Funktion fehlt
Parameter 1...). Erst, als ich die Funktion umbenannt habe, hat es geklap=
pt.
Die ge=E4nderte Datei h=E4ngt mit Anwendungsbeispiel an dieser Mail.
Vielan Dank auch!
Marian
--------------B13C9F8E8AF0168D1D18E3FE
Content-Type: text/plain; charset=us-ascii;
name="phpStockQuotes.php"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="phpStockQuotes.php"
<?php
class phpStockQuotes
{
// define class variables
var $symbol, $url;
var $last, $time, $change, $open, $high, $low, $volume;
function Quotes($symbol)
{
// save symbol
$this->symbol = $symbol;
// build url
$this->url = "http://de.finance.yahoo.com/d/quotes.csv?s=" . $this->symbol . "&f=sl1t1c1ghpv&e=.csv";
// get data from server
$this->get();
}
function get()
{
// try to open connection to finance.yahoo.com server
$fp = fopen( $this->url, "r" );
// check connection
if( $fp )
{
// read data
$data = fgets( $fp, 4096 );
// close conection
fclose( $fp );
// remove '"' characters from data
$data = ereg_replace( '"', "", $data );
// parse data and store values in class variables
list( $this->symbol, $this->last, $this->time, $this->change, $this->low, $this->high, $this->open, $this->volume ) = split( ",", $data );
}
}
}
// Anwendungsbeispiel
$symbol = "514350.F"; // Pixelpark Stammaktie in Frankfurt
$q = new phpStockQuotes;
$q->Quotes($symbol);
echo "<br>symbol: ".$q->symbol;
echo "<br>last: ".$q->last;
echo "<br>time: ".$q->time;
echo "<br>change: ".$q->change;
echo "<br>low: ".$q->low;
echo "<br>high: ".$q->high;
echo "<br>open: ".$q->open;
echo "<br>volume: ".$q->volume;
?>
--------------B13C9F8E8AF0168D1D18E3FE--
php::bar PHP Wiki - Listenarchive