简体   繁体   中英

Yahoo stock ticker is not working properly

I am working on stock ticker and search number of site for stock ticker. I found a ticker in this site .

But I am getting error while displaying the screen - where it is going wrong?

在此处输入图片说明

I feel error in below code, but I am not figuring it how to fix it.

        // ...format, and output them. I made the symbols into links to Yahoo's stock pages.
        echo "<span class=\"stockbox\"><a href=\"http://finance.yahoo.com/q?s=".$stock_info[0]."\">".$stock_info[0]."</a> ".sprintf("%.2f",$stock_info[1])." <span style=\"";
        // Green prices for up, red for down
        if ($stock_info[2]>=0) { echo "color: #009900;\">&uarr;";   }
        elseif ($stock_info[2]<0) { echo "color: #ff0000;\"> }
        echo sprintf("%.2f",abs($stock_info[2]))."</span></span>\n";
        // Done!
        fclose($local_file); 
    }
?>

您必须通过具有PHP支持的Web服务器运行它。

Your error exists on line 5:

elseif ($stock_info[2]<0) { echo "color: #ff0000;\"> }

Should be

elseif ($stock_info[2]<0) { echo "color: #ff0000;\">"; }

Or

elseif ($stock_info[2]<0) { echo 'color: #ff0000;">'; }

As a rule, I always do what I can to avoid escaping quotes , this forces me to know when a quote is closed or open. For example, I would rather do

echo "My name is '$bernard'";   
//and if the " quotes are compulsory
echo 'My name is "'.$bernard.'"';    

Than

echo "My name is \"bernard\"";

It's cleaner, and easier to read.

Update

I didn't notice the URL, it's a *.htm file. For the code to even run, you need to run it through a server that can process PHP code :)

您不会在此行上关闭引号:

elseif ($stock_info[2]<0) { echo "color: #ff0000;\"> }

Found the problem looked in the original site it said

"If it was a problem with the stockcache directory, the script would likely print “0.00 ↑0.00” for every stock entry. Rather, it looks as if your HTTP server is spitting out the PHP code instead of parsing it properly. This could be related to a server misconfiguration or conflicting code elsewhere on the page. Unfortunately, I can't be more specific without knowing much more of the context, such as the the source code of the webpage in question, server OS, HTTPD and PHP version, and their configurations."

looked up in the hosting help in found that it had to have php allowed (if it was within the html), had to create an .htaccess file an add the line the hosting company gave me, after a short chat with their support the issue was solved

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM