FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[php scripts ] phpweather&email





JANKOW
prognosis of weather

Code:
<?php
  /*
  $Id: phpweather.inc,v 1.17 2000/08/19 12:02:03 martin Exp $
  Copyright (c) 2000, Martin Geisler <gimpster@gimpster.com>. Licensed under the GPL
  See http://www.gimpster.com for further instructions on how to use PHP Weather.
  */

  /* Heres a good place to make a connection to the database.
     I strongly suggest that you make a table called metars as described
     below, so that PHP Weather can cache it's results for better
     performance.
     If you don't connect to the database you'll get some error about
     invalid MySQL result resources. These errors are harmless, but have
     been left in to remind you to make the database table :-) */


  function pretty_print_metar($metar, $location) {
    $data = process_metar($metar);
    extract($data);
    $minutes_old = round((time() - $time)/60);
    $gmtime = gmdate('H:i', $time);
    if(isset($cloud_layer1_altitude_ft)) {
      $sky_str = "The clouds were <b>$cloud_layer1_condition</b> at a height of <b>$cloud_layer1_altitude_m</b> meter (<b>$cloud_layer1_altitude_ft</b> feet).";
    } else {
      $sky_str = "The sky was <b>clear</b>.";
    }

    if(isset($visibility_miles)) {
      $visibility = "The visibility was <b>$visibility_km</b> kilometers (<b>$visibility_miles</b> miles).";
    }

    echo "<blockquote><p><b>$minutes_old</b> minutes ago, at <b>$gmtime</b> UTC, the wind was blowing at a speed of <b>$wind_meters_per_second</b> meters per second (<b>$wind_miles_per_hour</b> miles per hour) from <b>$wind_dir_eng</b> in $location. The temperature was <b>$temp_c</b> degrees Celsius (<b>$temp_f</b> degrees Fahrenheit), and the pressure was <b>$altimeter_hpa</b> hPa (<b>$altimeter_inhg</b> inHg). The relative humidity was <b>$rel_humidity%</b>. $sky_str $visibility</p></blockquote>\n";

  }



  function get_metar($station) {
    $query = "SELECT metar, UNIX_TIMESTAMP(timestamp) FROM metars WHERE station = '$station'";
    $result = mysql_query($query);
    if (mysql_num_rows($result)) {
      list($metar, $timestamp) = mysql_fetch_row($result);
      if ($timestamp > time() - 3600 - date('Z')) {
        /* We found the station, and the data is less than 1 hour old. */
        return $metar;
      } else {
        /* The data is old, we fetch a new METAR */
        return fetch_metar($station, 0);
      }
    } else {
      /* The station is new - we fetch a new METAR */
      return fetch_metar($station, 1);
    }
  }

  function fetch_metar($station, $new) {
    /* Retrieves the METAR from weather.noaa.gov and insert the data into the database.
       If $new is true, insert the metar, else just update. Returns the METAR. */
    $station = strtoupper($station);
    //  $file  = file("ftp://weather.noaa.gov/data/observations/metar/stations/$station.TXT");
    $file  = file("http://weather.noaa.gov/pub/data/observations/metar/stations/$station.TXT");
    $date  = trim(array_shift($file));
    $metar = trim(implode(' ', $file));
    $metar = str_replace('  ', ' ',$metar);
    if ($new) {
      $query = "INSERT INTO metars SET station = '$station', metar = '$metar', timestamp = '$date'";
    } else {
      $query = "UPDATE metars SET metar = '$metar', timestamp = '$date' WHERE station = '$station'";
    }
    mysql_query($query);
    return $metar;
  }


  function process_metar($metar) {
    /* Here we define the strings we need later.
       We put them in arrays, so that we can retrieve them efficiently. */
    $wind_dir_eng = array('North',
              'North/Northeast',
              'Northeast',
              'East/Northeast',
              'East',
              'East/Southeast',
              'Southeast',
              'South/Southeast',
              'South',
              'South/Southeast',
              'Southwest',
              'South/Southwest',
              'West',
              'West/Northwest',
              'Northwest',
              'North/Northwest',
              'North');
    $weather = array('PR' => 'Partial ',
             'BC' => 'Patches ',
             'DR' => 'Low Drifting ',
             'BL' => 'Blowing ',
             'SH' => 'Shower(s) ',
             'TS' => 'Thunderstorm ',
             'FZ' => 'Freezing',
             'DZ' => 'Drizzle ',
             'RA' => 'Rain ',
             'SN' => 'Snow ',
             'SG' => 'Snow Grains ',
             'IC' => 'Ice Crystals ',
             'PE' => 'Ice Pellets ',
             'GR' => 'Hail ',
             'GS' => 'Small Hail and/or Snow Pellets ',
             'UP' => 'Unknown ',
             'BR' => 'Mist ',
             'FG' => 'Fog ',
             'FU' => 'Smoke ',
             'VA' => 'Volcanic Ash ',
             'DU' => 'Widespread Dust ',
             'SA' => 'Sand ',
             'HZ' => 'Haze ',
             'PY' => 'Spray',
             'PO' => 'Well-Developed Dust/Sand Whirls ',
             'SQ' => 'Squalls ',
             'FC' => 'Funnel Cloud Tornado Waterspout ',
             'SS' => 'Sandstorm/Duststorm ');
    $cloud_condition = array('SKC' => 'clear',
                 'CLR' => 'clear',
                 'VV'  => 'vertical visibility',
                 'FEW' => 'few',
                 'SCT' => 'scattered',
                 'BKN' => 'broken',
                 'OVC' => 'overcast');
    $cloud_coverage = array('SKC' => '0',
                'CLR' => '0',
                'VV'  => '8/8',
                'FEW' => '1/8 - 2/8',
                'SCT' => '3/8 - 4/8',
                'BKN' => '5/8 - 7/8',
                'OVC' => '8/8');
   
    $decoded_metar['metar'] = $metar;
    $parts = explode(' ', $metar);
    $num_parts = count($parts);
    for ($i = 0; $i < $num_parts; $i++) {
      $part = $parts[$i];
      if ($part == 'METAR') {
        /* Type of Report: METAR */
        $decoded_metar['type'] = 'METAR';
      } elseif ($part == 'SPECI') {
        /* Type of Report: SPECI */
        $decoded_metar['type'] = 'SPECI';
      } elseif (ereg('^[A-Z]{4}$', $part) && ! isset($decoded_metar['station']))  {
        /* Station Identifier */
        $decoded_metar['station'] = $part;
      } elseif (ereg('([0-9]{2})([0-9]{2})([0-9]{2})Z', $part, $regs)) {
        /* Date and Time of Report
       We return a standard Unix UTC/GMT timestamp suitable for gmdate() */
        $decoded_metar['time'] = gmmktime($regs[2], $regs[3], 0, date('m'), $regs[1], date('Y'));
      } elseif ($part == 'AUTO') {
        /*  Report Modifier: AUTO */
        $decoded_metar['report_mod'] = 'AUTO';
      } elseif ($part == 'COR') {
        /*  Report Modifier: COR */
        $decoded_metar['report_mod'] = 'COR';
      } elseif (ereg('([0-9]{3}|VRB)([0-9]{2,3})(KT|G([0-9]{2,3})KT)', $part, $regs)) {
        /* Wind Group */

        if ($regs[1] == 'VRB') {
      $decoded_metar['wind_deg'] = 'Variable';
        } else {
      $decoded_metar['wind_deg'] = $regs[1];
      $decoded_metar['wind_dir_eng'] = $wind_dir_eng[round($regs[1]/22.5)];
        }
        /* The windspeed measured in knots: */
        $decoded_metar['wind_knots']             = $regs[2];
        /* The windspeed measured in meters per second, rounded to one decimal place: */
        $decoded_metar['wind_meters_per_second'] = number_format($regs[2] * 0.51444, 1);
        /* The windspeed measured in miles per hour, rounded to one decimal place: */
        $decoded_metar['wind_miles_per_hour']    = number_format($regs[2] * 1.1507695060844667, 1);
        if ($regs[4] != '') {
      /* We have a report with information about the gust.
         First we have the gust measured in knots: */
      $decoded_metar['wind_gust_knots']             = $regs[4] . ' knots';
      /* The gust measured in meters per second, rounded to one decimal place: */
      $decoded_metar['wind_gust_meters_per_second'] = number_format($regs[4] * 0.51444,1);
      /* The gust measured in miles per hour, rounded to one decimal place: */
      $decoded_metar['wind_gust_miles_per_hour']    = number_format($regs[2] * 1.1507695060844667, 1);
        }
      } elseif (ereg('([0-9]{3})V([0-9]{3})', $part, $regs)) {
        /* Variable wind-direction. */
        $decoded_metar['wind_var_beg'] = $regs[1];
        $decoded_metar['wind_var_end'] = $regs[2];
      } elseif ($part == 9999) {
        /* A strange value. When you look at other pages you see it interpreted like this (where I use > to signify 'Greater than'): */
        $decoded_metar['visibility_miles'] = '>7';
        $decoded_metar['visibility_km']    = '>11.3';
      } elseif (ereg('^M?[0-9]([0-9]*[0-5])?$', $part)) {
        /* Visibility Group */
        $decoded_metar['visibility_miles'] = $part;
      } elseif (ereg('M?(([0-9]?)[ ]?([0-9])(/?)([0-9]*))SM$', $decoded_metar['visibility_miles'].' '.$parts[$i], $regs)) {
        /* Visibility Group */
        if ($regs[4] == '/') {
      $vis_miles = $regs[2] + $regs[3]/$regs[5];
        } else {
      $vis_miles = $regs[1];
        }
        if ($regs[0][0] == 'M') {
      /* The visibility measured in miles, prefixed with < to indicate 'Less than' */
      $decoded_metar['visibility_miles'] = '<' . number_format($vis_miles, 1);
      /* The visibility measured in kilometers. The value is rounded
         to one decimal place, prefixed with < to indicate 'Less than' */
      $decoded_metar['visibility_km']    = '<' . number_format($vis_miles * 1.609344, 1);
        } else {
      /* The visibility measured in mile.s */
      $decoded_metar['visibility_miles'] = number_format($vis_miles, 1);
      /* The visibility measured in kilometers, rounded to one decimal place. */
      $decoded_metar['visibility_km']    = number_format($vis_miles * 1.609344, 1);
        }
      } elseif (ereg('^(-|\+|VC)?(TS|SH|FZ|BL|DR|MI|BC|PR|RA|DZ|SN|SG|GR|GS|PE|IC|UP|BR|FG|FU|VA|DU|SA|HZ|PY|PO|SQ|FC|SS|DS)+$', $part)) {
        /* We have a report about a specific weather-phenomenon (thunderstorm, hail etc.). */
        if ($part[0] == '-') {
      /* A light/moderate phenomenon */
      $decoded_metar['weather'] .= 'Light/moderate ';
      $part = substr($part, 1);
        } elseif ($part[0] == '+') {
      /* A heavy phenomenon */
      $decoded_metar['weather'] .= 'Heavy ';
      $part = substr($part, 1);
        } elseif ($part[0].$part[1] == 'VC') {
      /* Proximity Qualifier */
      $decoded_metar['weather'] .= 'Nearby ';
      $part = substr($part, 2);
        }
       
        while ($bite = substr($part, 0, 2)) {
      /* Now we take the first two letters and determine what they mean.
         We append this to the variable so that we gradually build up a phrase. */
      $decoded_metar['weather'] .= $weather[$bite];
      /* Here we chop off the two first letters, so that we can take a new bite at top of the while-loop. */
      $part = substr($part, 2);
        }
      } elseif (ereg('(SKC|CLR)', $part, $regs) || ereg('^(VV|FEW|SCT|BKN|OVC)([0-9]{3})(CB|TCU)?$', $part, $regs)) {
        /* We have found a cloud-layer-group. There can be up to three of these groups, so we store them as cloud_layer1, cloud_layer2 and cloud_layer3. */
        $cloud_layers++;
        /* Again we have to translate the code-characters to a meaningful string. */
        $decoded_metar['cloud_layer'. $cloud_layers.'_condition']    = $cloud_condition[$regs[1]];
        $decoded_metar['cloud_layer'.$cloud_layers.'_coverage']    = $cloud_coverage[$regs[1]];
        $decoded_metar['cloud_layer'.$cloud_layers.'_altitude_ft'] = $regs[2] *100;
        $decoded_metar['cloud_layer'.$cloud_layers.'_altitude_m']  = round($regs[2] * 30.48);
      } elseif (ereg('(M?[0-9]{2})/(M?[0-9]{2})?', $part, $regs)) {
        /* Temperature/Dew Point Group
       The temperature and dew-point measured in Celsius. */
        $decoded_metar['temp_c'] = strtr($regs[1], 'M', '-');
        $decoded_metar['dew_c']  = strtr($regs[2], 'M', '-');
        /* The temperature and dew-point measured in Fahrenheit, rounded to the nearest degree. */
        $decoded_metar['temp_f'] = round(strtr($regs[1], 'M', '-') * (9/5) + 32);
        $decoded_metar['dew_f']  = round(strtr($regs[2], 'M', '-') * (9/5) + 32);
      } elseif(ereg('A([0-9]{4})', $part, $regs)) {
        /* Altimeter */
        /* The pressure measured in inHg */
        $decoded_metar['altimeter_inhg'] = number_format($regs[1]/100, 2);
        /* The pressure measured in mmHg, hPa and atm */
        $decoded_metar['altimeter_mmhg'] = number_format($regs[1] * 0.254, 1);
        $decoded_metar['altimeter_hpa']  = number_format($regs[1] * 0.33863881578947);
        $decoded_metar['altimeter_atm']  = number_format($regs[1] * 3.3421052631579e-4, 3);
      } elseif(ereg('Q([0-9]{4})', $part, $regs)) {
        /* Altimeter - this is strange, the specification doesnt say anything about the Qxxxx-form, but it's in the METARs. */
        /* The pressure measured in hPa */
        $decoded_metar['altimeter_hpa']  = number_format($regs[1]);
        /* The pressure measured in mmHg, inHg and atm */
        $decoded_metar['altimeter_mmhg'] = number_format($regs[1] * 0.7500616827, 1);
        $decoded_metar['altimeter_inhg'] = number_format($regs[1] * 0.0295299875, 2);
        $decoded_metar['altimeter_atm']  = number_format($regs[1] * 9.869232667e-4, 3);
      } else {
        /* If we couldn't match the group, we assume that it was a remark. */
        $decoded_metar['remarks'] .= ' ' . $part;
      }
    }
    $decoded_metar['rel_humidity'] = number_format(100 *
      (
       610.710701 +
       44.4293573 * $decoded_metar['dew_c'] +
       1.41696846 * pow($decoded_metar['dew_c'], 2) +
       0.0274759545 * pow($decoded_metar['dew_c'], 3) +
       2.61145937E-4 * pow($decoded_metar['dew_c'], 4) +
       2.85993708E-6 * pow($decoded_metar['dew_c'], 5)
       )
      /
      (
       610.710701 +
       44.4293573 * $decoded_metar['temp_c'] +
       1.41696846 * pow($decoded_metar['temp_c'], 2) +
       0.0274759545 * pow($decoded_metar['temp_c'], 3) +
       2.61145937E-4 * pow($decoded_metar['temp_c'], 4) +
       2.85993708E-6 * pow($decoded_metar['temp_c'], 5)
       ), 1);
                       
    return $decoded_metar;
  }
  ?>
</body>
</html>



the skryp the checking the correctness of address email

Code:
<?
function disp_header()
{
global $PHP_SELF;
?>
<form method=post action=<?echo$PHP_SELF?>>
<input type=hidden name=sub value="ok">
Enter Email address <br>
<input type=text name=EMAIL size="20" value=<?echo$EMAIL?>>
&nbsp;
<input type=submit name=submit value=Check>
</form>
<?
}

if (empty($sub))
{
   disp_header();
}
elseif ($sub == "ok")
{
   $CHECK= strstr ($EMAIL, '@');
   $CHECK1= strstr ($CHECK, '.');
list( $name, $host) = split( '[@]', $EMAIL ); 
list( $host1, $host2, $host3) = split( '[.]', $host);
if ( ( ereg( "([~!#$%^&*])", $EMAIL)) || (!$CHECK) || ($CHECK == "@") ||
(!$CHECK1) || ( ereg( "([@])", $name)) || ($host1== "")    )
   {
   print "$EMAIL not valid Email Address\n"."<br>\n";
   }
   else
   {
      if ($name == "")
      {
      print "Entered email address <$EMAIL> is wrong\n";
      }
      else
      {
      Print "valid email address $EMAIL";
      }
   }           
}
?>

</body>
</html>
Related topics
Script php about gallery
HTTP AUTH with PHP and mySQL
How To : Improve Your PHP Programming
Mod's Installed and Custom PHP Scripts Made
Mod's Installed and Custom PHP Scripts Made
Tutorial: PHP Installed Modules Dynamic Reference Tool
Phoenix free PHP scripts
How to email data...
need php scripts installed - 120 Frih$'s
PHP scripts
PHP scripts not functioning.
know how much memory are your php scripts using
erratic behavior in my php scripts
Can i upload any types of file to 'Frihost' server?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.