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 Miguel Villase˝or  >  PHP Birthday To Age  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Birthday To Age
Calculate the age and other values from a birthday
Author: By
Last change:
Date: 1 year ago
Size: 2,044 bytes
 

Contents

Class file image Download
<?php
/**
 * example.php
 * 
 * @author Miguel Villase├▒or Gardu├▒o
 * 
 * Examples of use of the mkBirthday Class
 * 
 */
 
 
require "mkBirthday.php";
 
if(isset(
$_POST['action'])){
    
$birthday = new mkBirthday($_POST['date']);
    switch(
$_POST['action']){
        case 
'until':
            
$result $birthday->getDaysUntilNext()->format('%m months y %d days until next birthday');
            break;
        case 
'age':
            
$result $birthday->getAge()." years";
            break;
        case 
'is':
            
$result $birthday->isBirthday()?'true':'false';
            break;
    }
}
 
?>
<html lang="es">
    <head>
        <meta charset="utf-8">
        <title>MkBirthday Examples</title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        <script type="text/javascript">
            $(function() {
                $( "#date" ).datepicker({
                    dateFormat:'yy-mm-dd',
                    changeMonth: true,
                    changeYear: true
                });
            });
        </script>
    </head>
    <body>
        <h1>MkBirthday Class Examples</h1>
        <form method="post">
            <fieldset>
                <legend>Example</legend>
                <input type="text" name="date" id="date" />
                <select name="action">
                    <option value="until">Get days until next birthday</option>
                    <option value="age">Get age</option>
                    <option value="is">Is Birthday</option>
                </select>
                <input type="submit" />
                <br/>
                <?php
                
if(isset($_POST['action'])){
                    echo 
$result;
                }
                
?>
            </fieldset>
        </form>
        
    </body>
</html>