⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 home.php

📁 股票监视器是一个简单的实用工具
💻 PHP
字号:
<?php/** PHP STOCK TRACKER* -----------------* A multi-user utility for creating and managing stock* watchlists and historical analysis.* Copyright (C) 2005 Joshua Eldridge (joshuae74@hotmail.com)*** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License as published by* the Free Software Foundation; either version 2 of the License, or* (at your option) any later version.** This program is distributed in the hope that it will be useful,* but WITHOUT ANY WARRANTY; without even the implied warranty of* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the* GNU General Public License for more details.** You should have received a copy of the GNU General Public License* along with this program; if not, write to the Free Software* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA** See the COPYING file for full details.*/// Prevent this page from being accessed directly as// it should always be called from within index.phpif (!defined('IN_VALID')) {  die("Error: This File Cannot Be Accessed Directly");}require_once('inc/navigation.inc.php');// If the stocks data hasn't already been loaded into the session// load all the initial core information and save it to the session// info about all the stocks in a users watch list including:// id, symbol, name, exhange and date_addedif(!isset($_SESSION['user_stocks'])) {  $_SESSION['user_stocks'] = get_stocks_list($_SESSION['user_id']);}/* do some quick error checking in case this is the users first visit and there aren't any stocks in their watchlist*/if(count($_SESSION['user_stocks']) == 0) {	exit();}// Load the highs array using the batch function and cache the query.// Use the existing stocks session to pull the stock ids into a single array.// Store the results into the session if it hasn't already been loaded.if(!isset($_SESSION['user_highs'])) {  $ids_array = getSingleArray($_SESSION['user_stocks'], 'stock_id');  $_SESSION['user_highs'] = get_batch_high($ids_array);}// Load the stock_names array for use later ... foreach ($_SESSION['user_stocks'] as $full_name) {  $stock_names[$full_name['stock_symbol']] = $full_name['stock_name'];}/*print_r($_SESSION);echo '<pre>';print_r($ids);echo '</pre>';*/$date = getdate();// Simple tests to see if the market is trading// Doesn't take into account holidays or other unusual closuresif($date['hours'] > 16 || $date['hours'] < 10 || $date['weekday'] == "Saturday" || $date['weekday'] == "Sunday") {  $market_open = false;} else {  $market_open = true;}// Load the symbols array from the existing stocks session$symbols_array = getSingleArray($_SESSION['user_stocks'], 'stock_symbol');// Live query to Yahoo! to get the latest stock statistics$stock_stats = get_batch_yahoo($symbols_array);echo date("F j, Y, g:i:s a");echo '<table border="1" cellpadding="4" cellspacing="0">';// Build the row with the column header information. Will repeat the header every 30 rows.$column_labels =  '<tr bgcolor="' . $header_row . '"><td><b>Stock Name (Symbol)</b></td><td><b>';if($market_open === true) {  $column_labels .= 'Last Trade';} else {  $column_labels .= 'Close';}$column_labels .= '</b></td><td><b>Total Change</b></td><td><b>Opened</b></td><td><b>Low</b></td><td><b>High</b></td><td><b>Volume</b></td><td><b>52 Week High</b></td><td><b>52 Week Low</b></td></tr>';echo $column_labels;// The $row_primary and $row_secondary varibles come from the configuration file// This allows for different color schemes to be applied later.$bgcolor = $row_primary;// Iterate through the statistics received from Yahoo! and dump them into an// HTML table. $counter tracks the number of rows and determines when to draw the// column header row.foreach($stock_stats as $i) {  static $counter = 1;  if($counter == 30) {    echo $column_labels;    $counter = 1;  }/*The $i array looks like this:	[0] => AAPL				Ticker Symbol    [1] => 70.20			Closing Price/Last Trade    [2] => 1/14/2005		Trade Date    [3] => 4:00pm			Trade Time    [4] => +0.40			Percent Change    [5] => 70.25			Opening Price    [6] => 71.72			High Price    [7] => 69.19			Low Price    [8] => 31620512			Volume*/  echo '<tr bgcolor="' . $bgcolor . '"><td>';  echo '<b><a href="?pg=history&symbol=' . $i[0] . '" title="' . $stock_names[$i[0]] . '" id="' . $i[0] . '">' . $stock_names[$i[0]] . ' (' . $i[0] . ')</b>'; //SYMBOL    echo '</td><td>' . number_format($i[1],2) . '</td>'; // Closing Price/Last Trade  // Calculate the total change by subtracting the current price from the opening price  $total_change = round($i[1]-$i[5],2);  if ($total_change >= 0) {    echo '<td><span class="green">' . $total_change . '</span></td>';  } else {    echo '<td><span class="red">' . $total_change . '</span></td>';  }     echo '<td>' . number_format($i[5],2) . '</td>'; // Opening Price  echo '<td>' . number_format($i[7],2) . '</td>'; // Low Price  echo '<td>' . number_format($i[6],2) . '</td>'; // High Price  echo '<td>' . number_format($i[8]) . '</td>'; // Volume  echo '<td>' . number_format($_SESSION['user_highs'][$i[0]][0],2) . '</td>'; // 52 Week High  echo '<td>' . number_format($_SESSION['user_highs'][$i[0]][1],2) . '</td>'; // 52 Week Low  echo '</tr>';  // Alternate the background colors of rows for readability  // Use the colors defined in the config file for flexibility  if($bgcolor == $row_primary) {    $bgcolor = $row_secondary;  } else {    $bgcolor = $row_primary;  }  $counter++;}echo '</table>';?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -