I'm getting a JSON file that has the following data:
{
"Meta Data": {
"1. Information": "Daily Prices (open, high, low, close) and Volumes",
"2. Symbol": "GE",
"3. Last Refreshed": "2018-12-14 16:00:04",
"4. Output Size": "Compact",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2018-12-14": {
"1. open": "7.0800",
"2. high": "7.2500",
"3. low": "6.9950",
"4. close": "7.1000",
"5. volume": "128766603"
},
"2018-12-13": {
"1. open": "7.4900",
"2. high": "7.5000",
"3. low": "7.1200",
"4. close": "7.2000",
"5. volume": "207038918"
},
"2018-12-12": {
"1. open": "6.8400",
"2. high": "7.0250",
"3. low": "6.7000",
"4. close": "6.7100",
"5. volume": "105819951"
},
"2018-12-11": {
"1. open": "7.0400",
"2. high": "7.1300",
"3. low": "6.6600",
"4. close": "6.7600",
"5. volume": "124580597"
},
"2018-12-10": {
"1. open": "6.9700",
"2. high": "7.1200",
"3. low": "6.7500",
"4. close": "6.9300",
"5. volume": "112841778"
}
I want to retrieve data in PHP file to Display Stock open, High, Low, Close, Volume in a table format as attached below.
I tried:
$stockurl="http://alphavantage.co/…";
$json = file_get_contents($stockurl);
$obj1 = json_decode($json);
$obj =$obj1->{'Time Series (Daily)'};
$date = "2018-12-14";
$dataForSingleDate = $obj->{$date};
echo $dataForSingleDate->{'1. open'}.'<br/>';
echo $dataForSingleDate->{'2. high'}.'<br/>';
echo $dataForSingleDate->{'3. low'}.'<br/>';
echo $dataForSingleDate->{'4. close'}.'<br/>';
echo $dataForSingleDate->{'5. volume'}.'<br/>';
But i need to add date manualy and thats the probelm.