The following code is for a stock ticker, which should find a stock price and change, using the filename which is echoed in a url which searches Yahoo. However the echo does not appear to be working. I have highlighted where I think the problem is, but if anyone could help I would be very grateful.
<?php function getStockSite($stockLink){ if ($fp = fopen($stockLink, 'r')) { $content = ''; while ($line = fread($fp, 1024)) { $content .= $line; } } return $content; } function processStockSite($wurl){ $wrss = getStockSite($wurl); $name = '-'; $price = ''; $diff = ''; if (strlen($wrss)>100){ $spos = 0; // Get text $spos = strpos($wrss,':',$spos)+3; $spos = strpos($wrss,'',$spos); $epos = strpos($wrss,'',$spos); if ($epos>$spos){ $text = substr($wrss,$spos,$epos-$spos); } else { $text = '-'; } $spos = $epos + 10; // Get company name $epos = strpos($wrss,'<',$spos); if ($epos>$spos){ $name = substr($wrss,$spos,$epos-$spos); } // Get actual price $spos = strpos($wrss,'yfs_l10')+strlen('yfs_l10'); $spos = strpos($wrss,'>',$spos)+1; $epos = strpos($wrss,'<',$spos); if ($epos>$spos){ $price = substr($wrss,$spos,$epos-$spos); } else { $price = '-'; } // Get direction $spos = strpos($wrss,'alt',$epos)+strlen('alt')+2; $epos = strpos($wrss,'"',$spos); if ($epos>$spos){ $dir = strtolower(substr($wrss,$spos,$epos-$spos)); } // Get difference $spos = strpos($wrss,'>',$epos+3)+1; $epos = strpos($wrss,'<',$spos); if ($epos>$spos){ $diff = substr($wrss,$spos,$epos-$spos); } } $result['name'] = $name; $result['value'] = $price; $result['diff'] = $diff; $result['direction'] = $dir; $result['text'] = $text; return $result; } [COLOR="red"]$currentFile = $_SERVER["PHP_SELF"]; $parts = split('[./]', $currentFile); $epic = $parts[count($parts) - 2]; [/COLOR] $data = processStockSite('c:\q.htm'); [COLOR="Red"]$data = processStockSite('http://finance.yahoo.com/q?s=echo $epic.l'); [/COLOR] ?>
This displays the following:
Warning: fopen(http://finance.yahoo.com/q?s=echo $epic.l) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request in /hermes/web11b/b146/moo.3finking/company/zox.php on line 16
I have missed out 4 lines, so it is actually on line 12.
I have highlighted where I think the problem is, but I may be (and probably am) completely wrong.
Thanks for your help.