I am pretty new to php and I am having trouble with fopen. I am writing a script to be read into flash and display stocks into a scrolling ticker. Here is my script:
<?php
$symbol = array('^DJI' , '^IXIC' , '^GSPC' , '^RUT' , '^TMW' , '^GDAXI' , '^FTSE');
$RealName = array('DJIA' , 'NASDAQ' , 'S&P500' , 'Russell2000' , 'Wilshi5000' , 'DAX' , 'FTSE100');
$stockUp = '<font color="#009900">';
$stockDown = '<font color="#FF0000">';
$stockNoChange = '<font color="#FFDE42">';
$stockClose = '</font>';
echo 'text=';
$i = 0;
while($i <= 6)
{
$url = sprintf('http://finance.yahoo.com/d/quotes.csv?s ... gv&e=.csv/', $symbol[$i]);
$fp = fopen($url, 'r');
if(!$fp)
{
echo 'Error recieving stock information.';
}
else
{
$array = fgetcsv($fp , 4096 , ', ');
$sign = $array[4]{0};
switch ($sign)
{
case '+':
$status = $stockUp;
break;
case '-':
$status = $stockDown;
break;
default:
$status = $stockNoChange;
break;
}
fclose($fp);
}
echo urlencode($stockNoChange), urlencode($RealName[$i]) , '+' , urlencode($array[1]) , '+' , urlencode($stockClose) , urlencode($status) , urlencode($array[4]) , urlencode($stockClose), '+++' ;
$i++;
}
?>
It works fine on my local machine, but when I post it to my host, the page just loads for a long time and then I get the cannot find page error. Any help would be great. Thanks in advance.
Deric
fopen
Moderator: General Moderators
All my other pages will work fine. Just the ticker is giving me problems. I talked to my host and they told me there was something wrong my script and that I should get a new one!? I have uploaded the script a couple different times so I know the upload was okay. When I use another test server, not my local machine, I get a message that says:
text=
Warning: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /var/www/html/deric/Copy of ticker.php on line 17
Warning: fopen("http://finance.yahoo.com/d/quotes.csv?s ... =.csv/","r") - Bad file descriptor in /var/www/html/deric/Copy of ticker.php on line 17
Error recieving stock information.%3Cfont+color%3D%22%23FFDE42%22%3EDJIA++%3C%2Ffont%3E%3C%2Ffont%3E+++
Why would this happen? Again this is the same script that as seem above, but on another host.
Thanks for your response.
Deric
text=
Warning: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /var/www/html/deric/Copy of ticker.php on line 17
Warning: fopen("http://finance.yahoo.com/d/quotes.csv?s ... =.csv/","r") - Bad file descriptor in /var/www/html/deric/Copy of ticker.php on line 17
Error recieving stock information.%3Cfont+color%3D%22%23FFDE42%22%3EDJIA++%3C%2Ffont%3E%3C%2Ffont%3E+++
Why would this happen? Again this is the same script that as seem above, but on another host.
Thanks for your response.
Deric
Not too sure - but it could be that your server cannot resolve to dns, try http://64.58.76.190/d/quotes.csv?s=%s&f ... gv&e=.csv/ instead