PHP Script - Changes website color scheme according to market performance

Discussion in 'Chit Chat' started by OTM-Options, Jun 17, 2015.

  1. Below is a gimmicky PHP script that gets real-time market data from Yahoo Finance and will change a websites color-scheme based on how the market is doing - in this case SPY. You can also use PHP to extract real-time currency quotes from Yahoo Finance.


    • SPY up or down less than 0.60% = Blue Color Scheme
    • SPY up more than 0.60% = Green Color Scheme
    • SPY down more than 0.60% = Red Color Scheme
    • Could be used on a financial blog or forum.
    • Prerequisites: Interest in learning HTML, CSS and PHP.



    [​IMG]

    index.php
    Code:
    <html>
    <head>
    <link rel="stylesheet" type="text/css" href="styleMain.css">
    
    <?php
    $stock = "SPY";
    $open = fopen("http://finance.yahoo.com/d/quotes.csv?s=$stock&f=c", "r");
    $spy = fread($open, 2000);
    $results = substr($spy, -8, 5);
    fclose($open);
    
    if ($results >= 0.60) {
    $style = "styleGreen.css";
    }
    if ($results <= -0.60) {
    $style = "styleRed.css";
    }
    if ($results < 0.60 and $results > -0.60) {
    $style = "styleBlue.css";
    }
    $headline =  $stock . " ----- " . $results;
    ?>
    
    <link rel="stylesheet" type="text/css" href="<?php echo $style ?>">
    </head>
    <body>
    <h1><?php echo $headline ?></h1>
    <div class="cell1">
    <p>In 1974, Russia ........
    </div>
    <div class="cell2">
    <p>Trump spokeswoman .......
    </div>
    </body>
    </html>
    

    styleMain.css
    Code:
    body {
    color: #FFFFFF;
    }
    
    h1 {
    text-align: center;
    }
    
    .cell1 {
    color: #FFFFFF;
    border: 1px solid #FFFFFF;
    width: 750px;
    height: 200px;
    padding: 10px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 20px;
    }
    
    .cell2 {
    color: #FFFFFF;
    border: 1px solid #FFFFFF;
    width: 750px;
    height: 200px;
    padding: 10px;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 20px;
    }
    

    styleBlue.css
    Code:
    body {
    background-color: #0000CC;
    }
    
    .cell1 {
    background-color: #0033CC;
    }
    
    .cell2 {
    background-color: #0066CC;
    }
    

    styleGreen.css
    Code:
    body {
    background-color: #006633;
    }
    
    .cell1 {
    background-color: #009933;
    }
    
    .cell2 {
    background-color: #00CC33;
    }
    

    styleRed.css
    Code:
    body {
    background-color: #990000;
    }
    
    .cell1 {
    background-color: #CC0000;
    }
    
    .cell2 {
    background-color: #CC3300;
    }
    

    :)