I'm a complete beginner in php (and a first 'poster' here on SO) and seem to be missing something in a small script that I am doing from a tutorial.
What the script is basically suppose to do is get Ticker names from a hosted txt file on the server and output historical prices fetched from yahoo finance.
Everything seems to be working fine except that the content that i get from the getCSVfile function is incorrect (I get the html from the yahoo error page). The fetched URL is however correct and if I type in the targeted URL manually everything works just fine.
It is probably a basic mistake but can't seem to find it. Seems to be related to '' and ""s.
Many thanks in advance for the help Y
<?php
include("includes/connect.php");
function createURL($ticker){
$currentMonth = date('n') - 1;
$currentDay = date('j');
$currentYear = date('Y');
$result = 'http://ichart.finance.yahoo.com/table.csv? s='.$ticker.'&a=07&b=19&c=2012&d=11&e=08&f=2012 &g=d&ignore=.csv';
return (string)$result;
}
function getCSVFile($url, $outputFile){
$content = file_get_contents($url);
$content = str_replace('Date,Open,High,Low,Close,Volume,Adj Close','',$content);
$content = trim($content);
echo $content; /debugging
file_put_contents($outputFile,$content);
}
//test debugging - this is where the problem seems to be happening -
//the URL output is correct as is the getCSVfile but the combination of the two doesnt work properly//
$test = createURL('GOOG');
echo $test;
getCSVFile($test, "memory.txt");
/code continues...
?>