Manual of PHP

 
 
 

Web map

 
rim   rim
arrowReady frontarrow of Codes PHParrow hourly Areas

 

Hourly areas To print E-mail
Script PHP to extract a menu where to be able to choose the wished hourly area.

Others of the big needs caused by the distance between different countries and in some cases cities it is the hour.

For example: If a user is in any part of the world, how to do so that when it expresses an opinion, this one appears with his local time ó of his hourly area?

To solve this big problem and so many people others related to this genre we will use the hourly areas of the principal cities of the world.

We will use two crucial or decisive aspects the hour with regard to the meridian of the local city used as base to calculate the difference with regard to the distant city citing as an example the hour of the Meridian of Greenwich or hour 0 (zero).

Let's see the code source and then the explanation as of custom:

<?
if (isset ($_POST [hour])) {
   settype ($_POST [hour], "integer");
   settype ($_POST [min], "integer");
   settype ($_POST [seg], "integer");
   if ($_POST [hour] <=0 OR $_POST> [hour] 12) {
      I begin '<strong> incorrect Hour </strong>';
   } elseif ($_POST [min] <=0OR $_POST [min]> 60) {
      I begin '<strong> incorrect Minutes </strong>';
   } elseif ($_POST [seg] <=0 OR $_POST [seg]> 60) {
      I begin '<strong> Incorrect Seconds </strong>';
   } else {
      $hor=$_POST [hour];
      if ($_POST [tm] == 'pm' && $_POST [hour]> =1 && $_POST <[hour] 12) {
        $_POST [hour] + =12;
   }
   $total_minutos _ = floor ($_POST [hour] *60) +$_POST [min];
   $dia = "of the same day";
   if ($_POST [ciudad1]> =0) {//the area is positive h
      $gmt = (int) $total_minutos_-$_POST [ciudad1];
   } else {//it is negative
   $_POST [ciudad1] = (int) $_POST [ciudad1] *-1;
   $gmt = $total_minutos _ + $_POST [ciudad1];
   }
   if ($gmt <0) {
   $dia = 'of the previous day';
   $gmt + = 1440;//minutes of 1 day
   }
   if ($_POST [ciudad2]> 0) {
      $tiempo2=$_POST [ciudad2] +$total_minutos _;
   } else {
   $tiempo2=$_POST [ciudad2] +$gmt;
   if ($tiempo2> 1440)
   {
      $dia = "of the following day";
      $tiempo2 - = 1440;
   }
   if ($tiempo2 <0)
   {
      $dia = "of the previous day";
      $tiempo2 + = 1440;
   }
   }
$hora_de_la_otra_ciudad=floor ($tiempo2/60);

I begin 'In another city they are: '.$hora_de_la_otra_ciudad.': '.$_POST [min].': '.$_POST [seg].' '.$dia;
  }
} ?>

<form action = "<? do I begin $PHP_SELF?>" method = "post"> If in my PC they are
<unputt yam = "hour" type = "text" go = "hour" did I value = "<? do I begin $hor?>" size = "2" maxlength = "2">
:
<unputt yam = "min" type = "text" go = "min" value = "<? did "min" begin $_POST []?> "size = "2" maxlength = "2">
:
<unputt yam = "seg" type = "text" go = "seg" did I value = "<? do I begin $_POST ["seg"]?> "size = "2" maxlength = "2">
<select yam = "tm" go = "tm">
   <option I valued = "am"> am </option>
   <option I valued = "pm"> pm </option>
</select>
: and I am in:

<SELECT name=ciudad1 size=1 go = "ciudad1">
   <OPTION value=180> Addis Ababa </OPTION>
   <OPTION value=570> Adelaide </OPTION>
   <OPTION value=180> Aden </OPTION>
   <OPTION values =-360> Aklavik </OPTION>
   <OPTION value=60> Algiers </OPTION>
   <OPTION value=120> Amman </OPTION>
   <OPTION value=60> Amsterdam </OPTION>
   <OPTION value=720> Anadyr </OPTION>
   <OPTION value=120> Ankara </OPTION>
   <OPTION value=180> Antananarivo </OPTION>
   <OPTION values =-240> Asunció </OPTION>
   <OPTION value=120> Athens </OPTION>
   <OPTION values =-300> Atlanta </OPTION>
   <OPTION values =-360> Austin </OPTION>
   <OPTION value=0> Azores </OPTION>
   <OPTION value=180> Baghdad </OPTION>
   <OPTION value=420> Bangkok </OPTION>
   <OPTION value=60> Barcelona </OPTION>
   <OPTION value=180> Beirut </OPTION>
   <OPTION value=60> Belgrade </OPTION>
   <OPTION value=60> Berlin </OPTION>
   <OPTION values =-240> Bermuda </OPTION>
   <OPTION value=60> Bern </OPTION>
   <OPTION value=120> Biel </OPTION>
   <OPTION values =-300> Bogota </OPTION>
   <OPTION values =-300> Boston </OPTION>
   <OPTION values =-180> Brasilia </OPTION>
   <OPTION value=600> Brisbane </OPTION>
   <OPTION value=60> Brussels </OPTION>
   <OPTION value=120> Bucharest </OPTION>
   <OPTION value=60> Budapest </OPTION>
   <OPTION values =-180> Buenos Aires </OPTION>
   <OPTION value=330> Calcutta </OPTION>
   <OPTION values =-240 selected> Caracas </OPTION>
   <OPTION value=0> Casablanca </OPTION>
   <OPTION values =-300> Chicago </OPTION>
   <OPTION value=120> Cape Town </OPTION>
   <OPTION value=60> Copenhagen </OPTION>
   <OPTION values =-360> Dallas </OPTION>
   <OPTION value=180> Giving is Salaam </OPTION>
   <OPTION value=570> Darwin </OPTION>
   <OPTION values =-420> Denver </OPTION>
   <OPTION values =-300> Detroit </OPTION>
   <OPTION value=360> Dhaka </OPTION>
   <OPTION value=0> Dublin </OPTION>
   <OPTION values =-420> Edmonton </OPTION>
   <OPTION value=120> Istanbul </OPTION>
   <OPTION value=60> Stockholm </OPTION>
   <OPTION value=180> Cairo </OPTION>
   <OPTION value=60> Frankfurt </OPTION>
   <OPTION value=60> Geneva </OPTION>
   <OPTION values =-360> Guatemala </OPTION>
   <OPTION value=420> Hanoi </OPTION>
   <OPTION value=120> Harare </OPTION>
   <OPTION value=120> Helsinki </OPTION>
   <OPTION value=420> Ho Chi Minh City </OPTION>
   <OPTION value=480> Hong Kong </OPTION>
   <OPTION value=600> Honolulu </OPTION>
   <OPTION values =-360> Houston </OPTION>
   <OPTION values =-300> Indianápolis </OPTION>
   <OPTION value=300> Islamabad </OPTION>
   <OPTION value=420> Jakarta </OPTION>
   <OPTION value=120> Jerusalem </OPTION>
   <OPTION value=120> Johannesburg </OPTION>
   <OPTION value=270> Kabúl </OPTION>
   <OPTION value=720> Kamchatka </OPTION>
   <OPTION value=300> Kathmandú </OPTION>
   <OPTION value=120> Khartoum </OPTION>
   <OPTION value=120> Kigali </OPTION>
   <OPTION values =-300> Kingston </OPTION>
   <OPTION value=480> Kuala Lumpur </OPTION>
   <OPTION value=180> Kuwait </OPTION>
   <OPTION values =-240> Havana </OPTION>
   <OPTION values =-240> La Paz </OPTION>
   <OPTION value=0> Las Palmas </OPTION>
   <OPTION value=60> Lagos </OPTION>
   <OPTION values =-300> Lima </OPTION>
   <OPTION value=0> Lisbon </OPTION>
   <OPTION value=0> London </OPTION>
   <OPTION values =-480> Los Angeles </OPTION>
   <OPTION value=60> Madrid </OPTION>
   <OPTION values =-360> Managua </OPTION>
   <OPTION value=480> Manila </OPTION>
   <OPTION value=240> Masqat </OPTION>
   <OPTION value=600> Melburne </OPTION>
   <OPTION values =-360> Mexico D.F. </OPTION>
   <OPTION value=300> Miami </OPTION>
   <OPTION value=60> Milan </OPTION>
   <OPTION values =-360> Minneápolis </OPTION>
   <OPTION values =-180> Montevideo </OPTION>
   <OPTION values =-300> Montreal </OPTION>
   <OPTION value=180> Moscow </OPTION>
   <OPTION value=330> Mumbai </OPTION>
   <OPTION value=60> Munich </OPTION>
   <OPTION value=180> Nairobi </OPTION>
   <OPTION value=60> Naples </OPTION>
   <OPTION values =-300> Nassau </OPTION>
   <OPTION value=330> New Delhi </OPTION>
   <OPTION values =-360> New Orleans </OPTION>
   <OPTION values =-300> New York </OPTION>
   <OPTION value=60> Oslo </OPTION>
   <OPTION values =-240> Ottawa </OPTION>
   <OPTION value=60> Paris </OPTION>
   <OPTION value=480> Pequín </OPTION>
   <OPTION value=480> Perth </OPTION>
   <OPTION values =-420> Phoenix </OPTION>
   <OPTION value=420> Phnom Penh </OPTION>
   <OPTION value=60> Prague </OPTION>
   <OPTION value=540> Pyongyang </OPTION>
   <OPTION value=0> Reykjavik </OPTION>
   <OPTION values =-180> Rio de Janeiro </OPTION>
   <OPTION value=180> Riyadh </OPTION>
   <OPTION value=60> Rome </OPTION>
   <OPTION values =-240> St. John's </OPTION>
   <OPTION values =-360> St. Paul </OPTION>
   <OPTION values =-480> San Francisco </OPTION>
   <OPTION values =-240> Saint John </OPTION>
   <OPTION values =-360> San Salvador </OPTION>
   <OPTION values =-300> Santo Domingo </OPTION>
   <OPTION values =-240> Santiago </OPTION>
   <OPTION values =-180> Sao Paulo </OPTION>
   <OPTION values =-480> Seattle </OPTION>
   <OPTION value=540> Seoul </OPTION>
   <OPTION value=480> Shanghai </OPTION>
   <OPTION value=480> Singapore </OPTION>
   <OPTION value=60> Sofia </OPTION>
   <OPTION value=720> Suva </OPTION>
   <OPTION value=600> Sydney </OPTION>
   <OPTION value=480> Taipei </OPTION>
   <OPTION value=120> Tallinn </OPTION>
   <OPTION value=300> Tashkent </OPTION>
   <OPTION values =-210> Teheran </OPTION>
   <OPTION value=540> Tokyo </OPTION>
   <OPTION values =-300> Toronto </OPTION>
   <OPTION value=60> Turin </OPTION>
   <OPTION values =-300> Vancúver </OPTION>
   <OPTION value=60> Warsaw </OPTION>
   <OPTION value=60> Venice </OPTION>
   <OPTION value=60> Vienna </OPTION>
   <OPTION value=600> Vladivostok </OPTION>
   <OPTION values =-300> Washington </OPTION>
   <OPTION value=720> Wellington </OPTION>
   <OPTION values =-360> Winnipeg </OPTION>
   <OPTION value=390> Yangon </OPTION>
   <OPTION value=60> Zagreb </OPTION>
   <OPTION value=60> Zurick </OPTION>
</SELECT>
<br>
Then in

<SELECT name=ciudad2 size=1 go = "ciudad2">
   <OPTION value=180> Addis Ababa </OPTION>
   <OPTION value=570> Adelaide </OPTION>
   <OPTION value=180> Aden </OPTION>
   <OPTION values =-360> Aklavik </OPTION>
   <OPTION value=60> Algiers </OPTION>
   <OPTION value=120> Amman </OPTION>
   <OPTION value=60> Amsterdam </OPTION>
   <OPTION value=720> Anadyr </OPTION>
   <OPTION value=120> Ankara </OPTION>
   <OPTION value=180> Antananarivo </OPTION>
   <OPTION values =-240> Asunció </OPTION>
   <OPTION value=120> Athens </OPTION>
   <OPTION values =-300> Atlanta </OPTION>
   <OPTION values =-360> Austin </OPTION>
   <OPTION value=0> Azores </OPTION>
   <OPTION value=180> Baghdad </OPTION>
   <OPTION value=420> Bangkok </OPTION>
   <OPTION value=60> Barcelona </OPTION>
   <OPTION value=180> Beirut </OPTION>
   <OPTION value=60> Belgrade </OPTION>
   <OPTION value=60> Berlin </OPTION>
   <OPTION values =-240> Bermuda </OPTION>
   <OPTION value=60> Bern </OPTION>
   <OPTION value=120> Biel </OPTION>
   <OPTION values =-300> Bogota </OPTION>
   <OPTION values =-300> Boston </OPTION>
   <OPTION values =-180> Brasilia </OPTION>
   <OPTION value=600> Brisbane </OPTION>
   <OPTION value=60> Brussels </OPTION>
   <OPTION value=120> Bucharest </OPTION>
   <OPTION value=60> Budapest </OPTION>
   <OPTION values =-180> Buenos Aires </OPTION>
   <OPTION value=330> Calcutta </OPTION>
   <OPTION values =-240> Caracas </OPTION>
   <OPTION value=0> Casablanca </OPTION>
   <OPTION values =-300> Chicago </OPTION>
   <OPTION value=120> Cape Town </OPTION>
   <OPTION value=60> Copenhagen </OPTION>
   <OPTION values =-360> Dallas </OPTION>
   <OPTION value=180> Giving is Salaam </OPTION>
   <OPTION value=570> Darwin </OPTION>
   <OPTION values =-420> Denver </OPTION>
   <OPTION values =-300> Detroit </OPTION>
   <OPTION value=360> Dhaka </OPTION>
   <OPTION value=0> Dublin </OPTION>
   <OPTION values =-420> Edmonton </OPTION>
   <OPTION value=120> Istanbul </OPTION>
   <OPTION value=60> Stockholm </OPTION>
   <OPTION value=180> Cairo </OPTION>
   <OPTION value=60> Frankfurt </OPTION>
   <OPTION value=60> Geneva </OPTION>
   <OPTION values =-360> Guatemala </OPTION>
   <OPTION value=420> Hanoi </OPTION>
   <OPTION value=120> Harare </OPTION>
   <OPTION value=120> Helsinki </OPTION>
   <OPTION value=420> Ho Chi Minh City </OPTION>
   <OPTION value=480> Hong Kong </OPTION>
   <OPTION value=600> Honolulu </OPTION>
   <OPTION values =-360> Houston </OPTION>
   <OPTION values =-300> Indianápolis </OPTION>
   <OPTION value=300> Islamabad </OPTION>
   <OPTION value=420> Jakarta </OPTION>
   <OPTION value=120> Jerusalem </OPTION>
   <OPTION value=120> Johannesburg </OPTION>
   <OPTION value=270> Kabúl </OPTION>
   <OPTION value=720> Kamchatka </OPTION>
   <OPTION value=300> Kathmandú </OPTION>
   <OPTION value=120> Khartoum </OPTION>
   <OPTION value=120> Kigali </OPTION>
   <OPTION values =-300> Kingston </OPTION>
   <OPTION value=480> Kuala Lumpur </OPTION>
   <OPTION value=180> Kuwait </OPTION>
   <OPTION values =-240> Havana </OPTION>
   <OPTION values =-240> La Paz </OPTION>
   <OPTION value=0> Las Palmas </OPTION>
   <OPTION value=60> Lagos </OPTION>
   <OPTION values =-300> Lima </OPTION>
   <OPTION value=0> Lisbon </OPTION>
   <OPTION value=0> London </OPTION>
   <OPTION values =-480> Los Angeles </OPTION>
   <OPTION value=60> Madrid </OPTION>
   <OPTION values =-360> Managua </OPTION>
   <OPTION value=480> Manila </OPTION>
   <OPTION value=240> Masqat </OPTION>
   <OPTION value=600> Melburne </OPTION>
   <OPTION values =-360> Mexico D.F. </OPTION>
   <OPTION value=300> Miami </OPTION>
   <OPTION value=60> Milan </OPTION>
   <OPTION values =-360> Minneápolis </OPTION>
   <OPTION values =-180> Montevideo </OPTION>
   <OPTION values =-300> Montreal </OPTION>
   <OPTION value=180> Moscow </OPTION>
   <OPTION value=330> Mumbai </OPTION>
   <OPTION value=60> Munich </OPTION>
   <OPTION value=180> Nairobi </OPTION>
   <OPTION value=60> Naples </OPTION>
   <OPTION values =-300> Nassau </OPTION>
   <OPTION value=330> New Delhi </OPTION>
   <OPTION values =-360> New Orleans </OPTION>
   <OPTION values =-300> New York </OPTION>
   <OPTION value=60> Oslo </OPTION>
   <OPTION values =-240> Ottawa </OPTION>
   <OPTION value=60> Paris </OPTION>
   <OPTION value=480> Pequín </OPTION>
   <OPTION value=480> Perth </OPTION>
   <OPTION values =-420> Phoenix </OPTION>
   <OPTION value=420> Phnom Penh </OPTION>
   <OPTION value=60> Prague </OPTION>
   <OPTION value=540> Pyongyang </OPTION>
   <OPTION value=0> Reykjavik </OPTION>
   <OPTION values =-180> Rio de Janeiro </OPTION>
   <OPTION value=180> Riyadh </OPTION>
   <OPTION value=60> Rome </OPTION>
   <OPTION values =-240> St. John's </OPTION>
   <OPTION values =-360> St. Paul </OPTION>
   <OPTION values =-480> San Francisco </OPTION>
   <OPTION values =-240> Saint John </OPTION>
   <OPTION values =-360> San Salvador </OPTION>
   <OPTION values =-300> Santo Domingo </OPTION>
   <OPTION values =-240> Santiago </OPTION>
   <OPTION values =-180> Sao Paulo </OPTION>
   <OPTION values =-480> Seattle </OPTION>
   <OPTION value=540> Seoul </OPTION>
   <OPTION value=480> Shanghai </OPTION>
   <OPTION value=480> Singapore </OPTION>
   <OPTION value=60> Sofia </OPTION>
   <OPTION value=720> Suva </OPTION>
   <OPTION value=600> Sydney </OPTION>
   <OPTION value=480> Taipei </OPTION>
   <OPTION value=120> Tallinn </OPTION>
   <OPTION value=300> Tashkent </OPTION>
   <OPTION values =-210> Teheran </OPTION>
   <OPTION value=540> Tokyo </OPTION>
   <OPTION values =-300> Toronto </OPTION>
   <OPTION value=60> Turin </OPTION>
   <OPTION values =-300> Vancúver </OPTION>
   <OPTION value=60> Warsaw </OPTION>
   <OPTION value=60> Venice </OPTION>
   <OPTION value=60> Vienna </OPTION>
   <OPTION value=600> Vladivostok </OPTION>
   <OPTION values =-300 selected> Washington </OPTION>
   <OPTION value=720> Wellington </OPTION>
   <OPTION values =-360> Winnipeg </OPTION>
   <OPTION value=390> Yangon </OPTION>
   <OPTION value=60> Zagreb </OPTION>
   <OPTION value=60> Zurick </OPTION>
</SELECT>
they are

<unputt type = "submit" values = "to See hour"> </form>

Explanation:

First of all we will initiate a condition to verify if $_POST [hour] it has been defined in some moment across the function isset (); (it will only take value when information is sent across HTTP-POST)

We will change the type of fact of $_POST [hour], $_POST [min] and $_POST [second] of String or Chain to Integer or Point across the function settype ():

We will realize a ratification with a series of conditions to verify:

Yes The Value is minor than 0 (zero) or major than 12 ó 60 as it is the case, of all these situations are opposite we will initiate the assembly of a series of instructions.

Condition: if ($_POST [tm] == 'pm' && $_POST [hour]> =1 && $_POST <[hour] 12)

We express if the hour is PM but also this hour must be major or just as 1 and minor than 12, so if he evaluates TRUE 24 will make us take the hour to in base:

For example: if PM is inserted 1 HOUR we must take it at 13 hours, for it we add $_POST [hour] more 12 hours passed like constant.

Then we associate with the variable $total_minutos_el value returned by the multiplication between $_POST [hour] and 60 more minutes “$_POST [min]” rounded down by means of the mathematical function floor (), to take the expression of Hora:Minutos to entire minutes.

We define the value of the variable $dia, this value will be supported any time the circumstances like that tolerate it, since it can be changed or remplazado if some of the subsequent conditions evaluates TRUE.

Yes $_POST [ciudad1] it is major or equal to 0,

Let's remember that the value of $_POST [ciudad1] will be the hour with regard to the meridian of the occupied city like reference, This point can be negative or positive and this condition will evaluate alone TRUE if it is positive; to realize a subtraction between $total_minutos_ and the value of $_POST [ciudad1] associating it with the variable $gmt.

Otherwise to himself $_POST [ciudad1] it is major or equal to 0,

It means that $_POST [ciudad1] it is negative and we will spend it to positive, multiplying it by-1.
$_POST [ciudad1] *-1;
And we realize a sum between $_POST [ciudad1] and $total_minutos _, the opposite of the previous case.

So that and with that sense?

We must determine if the resultant value is positive or negative to state if the difference is of the previous day or of the following day.

If it is minor to 0 (negative)
We change the value previously assigned to $dia for previous day and add him to $gmt "1440" entire minutes of one day.

Yes $_POST [ciudad2] it is major than 0, it is to the east of the meridian

We add up $tiempo2 and $total_minutos _, and associate it to $tiempo2.

Otherwise than Himself $_POST [ciudad2] it is bigger than 0.

We realize an operation similar to the previous one but this time we add the value of $gmt, defined in previous processes.

Inside this frame we realize two more conditions:

If $tiempo2 it is major than the whole of minutes of one day (1440), then it is the following day.
If $tiempo2 it is minor that 0 then is of the previous day.

Finally without importing the used routine we return the result, transforming these resultant minutes in hours: for it we will divide it between 60 and we round this value down, associate the result with the variable: $hora_de_la_otra_ciudad

And we give exit to the navigator by means of one I begin.

Emmanuel García of Expensive
http://www.blasten.com/contenidos/19100

 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

hollywood gossips , saturn phone cards , Isla Mujeres properties , speed test , Holzhaus , Replica Watches , Hotels Booking