-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.yahoostock.php
More file actions
80 lines (68 loc) · 1.48 KB
/
Copy pathclass.yahoostock.php
File metadata and controls
80 lines (68 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* Class to fetch stock data from Yahoo! Finance
*
*/
class YahooStock {
/**
* Array of stock code
*/
private $stocks = array();
/**
* Parameters string to be fetched
*/
private $format;
/**
* Populate stock array with stock code
*
* @param string $stock Stock code of company
* @return void
*/
public function addStock($stock)
{
$this->stocks[] = $stock;
}
/**
* Populate parameters/format to be fetched
*
* @param string $param Parameters/Format to be fetched
* @return void
*/
public function addFormat($format)
{
$this->format = $format;
}
/**
* Get Stock Data
*
* @return array
*/
public function getQuotes()
{
$result = array();
$format = $this->format;
foreach ($this->stocks as $stock)
{
/**
* fetch data from Yahoo!
* s = stock code
* f = format
* e = filetype
*/
$s = file_get_contents("http://download.finance.yahoo.com/d/quotes.csv?s=$stock&f=$format&e=.csv");
/**
* Cleaned up the name column so it fits in one cell
*/
$t = str_replace( ', Inc', '', $s );
/**
* convert the comma separated data into array
*/
$data = explode( ',', $t);
/**
* populate result array with stock code as key
*/
$result[$stock] = $data;
}
return $result;
}
}