Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tim Akinbo  >  NuSOAP  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: A webservice client using the NuSOAP toolkit to display company stock information.
Class: NuSOAP
A SOAP toolkit that can be used for webservices
Author: By
Last change:
Date: 2003-01-12 22:15
Size: 3,802 bytes
 

Contents

Class file image Download
<?php

/*
 * Company Information
 * This script is a webservice client that consumes the webservice with
 * WSDL document at http://www.flash-db.com/services/ws/companyInfo.wsdl
 *
 * Given any stock symbol, it queries the webservice for information about
 * that stock symbol and it retrieves the results from the webservice 
 * for display.
 *
 * A live demo of this program can be found at
 * http://timba.host.sk/companyinfo.php
 *
 * I actually noticed that NuSOAP doesn't have very good documentation
 * and I was thinking of writing one. I am working on my site at
 * http://timba.host.sk/ and when I am through with it, I would be putting 
 * the documentation there.
 *
 * Written by: 
 *    Tim Akinbo
 *    Department of Electronic and Electrical Engineering,
 *    Obafemi Awolowo University,
 *    Ile-Ife, Osun State, Nigeria
 *
 * Date: January 12, 2003: 23:10:10 GMT+0100
 *
 */

 // Include the NuSOAP soap toolkit file.
 
include('nusoap.php');
 
 
// Create a SOAP Client object.
 
$client = new soapclient("http://www.flash-db.com/services/ws/companyInfo.wsdl","wsdl");
 
 
// The following is a mechanism for capturing the stock symbol we want
 // to lookup. You can change this as required.
 
$symbol $_GET['symbol'];
 
 
// Arguments for the webservice.
 
$args = array ("username"=>"Any""password"=>"Any""ticker"=>$symbol);
 
 
// Call the webservice "doCompanyInfo" method with the arguments.
 
$results $client->call("doCompanyInfo"$args);
 
 
/* $results is an array with the following structure
     
     Array
    (
            [symbol] => MU
        [company] => MICRON TECH
        [lastPrice] => 10.29
        [tradedDate] => 1/10/2003
        [tradedTime] => 4:01pm
        [change] => 0.34
        [changePercent] => +3.42%
        [volumne] => 8895900
           [averageVolume] => 9653090
            [bid] => N/A
            [ask] => N/A
            [yesterdayClose] => 9.95
            [open] => 10.04
            [yearHigh] => 39.5
            [yearLow] => 9.40 
            [dayLow] => 9.90 
            [dayHigh] => 10.38
            [earnPerShare] => -1.59
            [PE] => N/A
            [divDate] =>  1-May-00
            [yeild] => 0
            [divShare] => N/A
            [marketCap] => 6.226B
    )
 */

 // We would now format the data for output in HTML.
 
$html "<html>\n<head>\n<title>Company Info. Webservice client - Written by: Tim Akinbo</title>\n</head>\n";
 
$html .= "<body>\n";
 
$html .= "<table cellpadding=\"1\" cellspacing=\"0\" border=\"0\" width=\"300\" bgcolor=\"#CCCCCC\">\n<tr>\n";
 
$html .= "<td><font face=\"Tahoma, Arial\" size=\"2\">&nbsp;Company Info</font></td>\n";
 
$html .= "</tr>\n<tr>\n<td>\n<table cellpadding=\"4\" cellspacing=\"0\" border=\"0\" width=\"100%\" bgcolor=\"#FFFFFF\">\n<tr>\n";
 
$html .= "<td><font face=\"Tahoma, Arial\" size=\"1\"><strong>Company Name</strong></font></td><td><font face=\"Tahoma, Arial\" size=\"1\"><strong>Stock Symbol</strong></font></td><td><font face=\"Tahoma, Arial\" size=\"1\"><strong>Percentage Change</strong></font></td>\n</tr>\n";
 
 
$color "#000000";
 
 
// $color is set to green if we have an appreciation in value ("+" present in $results['changePercent'])
 
if (preg_match("/^\+/"$results['changePercent'])) $color "#00CC33";
 
 
// else it is set to red if we have a depreciation ("-")
 
if (preg_match("/^-/"$results['changePercent'])) $color "#FF0000";
 
 
$html .= "<tr>\n<td><font face=\"Tahoma, Arial\" size=\"1\">" $results['company'] . "</font></td><td><font face=\"Tahoma, Arial\" size=\"1\">" $results['symbol'] . "</font></td><td><font face=\"Tahoma, Arial\" size=\"1\" color=\"$color\"><strong>" $results['changePercent'] . "</strong></font></td>\n</tr>\n";
 
$html .= "</table>\n</td>\n</tr>\n</table>\n</body>\n</html>";
 
 echo 
$html;

?>