Browse Source

Usable version.

Frederic G. MARAND 11 years ago
parent
commit
e98ac9f194
2 changed files with 70 additions and 2 deletions
  1. 20 0
      date/date.inc
  2. 50 2
      date/date.php

+ 20 - 0
date/date.inc

@@ -0,0 +1,20 @@
+<?php
+class DateFormatter {
+  const DEFAULT_FORMAT = 'l Y-m-d';
+
+  public $format;
+  public $time;
+
+  public function __construct() {
+    if (!empty($_REQUEST['apply'])) {
+      $this->format = $_REQUEST['format'];
+    }
+    else {
+      $this->format = self::DEFAULT_FORMAT;
+    }
+  }
+
+  public function date() {
+    return date($this->format, time());
+  }
+}

+ 50 - 2
date/date.php

@@ -1,3 +1,51 @@
 <?php
-?>
-<iframe src="http://fr2.php.net/manual/fr/function.date.php" />
+header('Content-type: text/html; charset=utf-8');
+require __DIR__ . '/date.inc';
+
+$formatter = new DateFormatter();
+?><!DOCTYPE html>
+<html>
+  <head>
+    <style type="text/css">
+      .fullpage {
+        width: 100%;
+        height: 100%;
+      }
+      .fullpage iframe {
+        width: 90%;
+        height: 80em;
+      }
+      </style>
+    </head>
+  <body>
+    <table class="fullpage">
+      <tr>
+        <td valign="top" width="40%">
+          <h1>Date helper</h1>
+          <p>Saisissez une chaine de format de date PHP dans le champ ci-dessous,
+            et le site vous renverra la date courante sous le format indiqué.</p>
+          <p>Le cadre à droite contient la documentation de référence de la
+            fonction PHP date().</p>
+          <form method="POST">
+            <table>
+              <tr>
+                <td><label for="format">Format:</label></td>
+                <td><input type="text" name="format" value="<?php echo $formatter->format; ?>" /></td>
+                </tr>
+              <tr>
+                <td><label for="result">Résultat:</label></td>
+                <td><input disabled="disabled" type="text" name="result" value="<?php echo $formatter->date(); ?>" /></td>
+                </tr>
+              </table>
+            <input type="submit" name="apply" value="Formater" />
+            <input type="submit" name="reset" value="Valeur par défaut" />
+            </form>
+          </td>
+        <td valign="top">
+          <iframe
+            src="http://fr2.php.net/manual/fr/function.date.php#refsect1-function.date-parameters" />
+          </td>
+        </tr>
+      </table>
+    </body>
+  </html>