Question

Hi I am writing a program were I am sending an http request to a website in order to get a csv file. However I am doing this multiple times using a loop and I need it to change according to the variable I am inputting.

$data_file = simple_load_file("xml data set with stock tickers");

$symbol = $data_file->quote[$loop]->symbol;

$data_file_dividend_csv = file_get_contents("http://ichart.finance.yahoo.com/table.csv?s=$symbol&a=01&b=01&c=2014&d=02&e=02&f=2014&g=v&ignore=.csv");

Any help would be appreciated, thanks in advance

Was it helpful?

Solution

You can just concatenate your string with variable as follow

$data_file_dividend_csv = file_get_contents('http://ichart.finance.yahoo.com/table.csv?s='.$symbol.'&a=01&b=01&c=2014&d=02&e=02&f=2014&g=v&ignore=.csv');

OTHER TIPS

PHP will parse and substitute variables located inside double-quoted strings. There are two different syntax forms for this. I prefer the complex syntax to avoid misinterpretation of variable names.

In your case, you can use the following

$data_file_dividend_csv = file_get_contents("http://ichart.finance.yahoo.com/table.csv?s={$symbol}&a=01&b=01&c=2014&d=02&e=02&f=2014&g=v&ignore=.csv");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top