realwx
01-30-2007, 10:55 AM
How do I do a PHP script inside a template, e.g. the forum description? I'm an expert at PHP scripting however I'm new to vBulletin plugins. What I'm trying to do is this:
$template = '%stock%: <b>%price%</b> (%change%)';
function stocks($template, $stock) {
$data = file_get_contents("http://download.finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgv&e=.csv");
$data = explode(",", $data);
$current = round($data[1], 2);
$up = round($data[4], 2);
$template = str_replace("%stock%",$stock, $template);
$template = str_replace("%price%",$current, $template);
$template = str_replace("%change%", $up, $template);
return $template;
}
//vb would call "stocks($template, "AAPL")"
And then the forum description would input as:
The forum for all stock market talk! Apple stock info: $stocks
and translate it into:
The forum for all stock market talk! Apple stock info: AAPL: $88.88 (+8.88)
Where $stocks would be stocks($template, "AAPL").
Can somebody please help me out with this?
EDIT: Sorry, accidentally put in wrong forum. :o
$template = '%stock%: <b>%price%</b> (%change%)';
function stocks($template, $stock) {
$data = file_get_contents("http://download.finance.yahoo.com/d/quotes.csv?s=$stock&f=sl1d1t1c1ohgv&e=.csv");
$data = explode(",", $data);
$current = round($data[1], 2);
$up = round($data[4], 2);
$template = str_replace("%stock%",$stock, $template);
$template = str_replace("%price%",$current, $template);
$template = str_replace("%change%", $up, $template);
return $template;
}
//vb would call "stocks($template, "AAPL")"
And then the forum description would input as:
The forum for all stock market talk! Apple stock info: $stocks
and translate it into:
The forum for all stock market talk! Apple stock info: AAPL: $88.88 (+8.88)
Where $stocks would be stocks($template, "AAPL").
Can somebody please help me out with this?
EDIT: Sorry, accidentally put in wrong forum. :o

