fopen

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ddpicha
Forum Newbie
Posts: 4
Joined: Sat Jul 06, 2002 5:41 pm

fopen

Post by ddpicha »

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
Elfstone
Forum Newbie
Posts: 21
Joined: Tue Jun 11, 2002 2:25 am
Location: NJ, USA

Post by Elfstone »

That sounds more like a problem with your host than with your script if you're getting an error where it can't find the page. Did the file upload properly? Are any of your other pages working?
ddpicha
Forum Newbie
Posts: 4
Joined: Sat Jul 06, 2002 5:41 pm

Post by ddpicha »

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
sandz
Forum Newbie
Posts: 3
Joined: Wed May 29, 2002 5:58 pm

Post by sandz »

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
Post Reply