Golden mean calculator for a given length of time


/ Published in: PHP
Save to your folder(s)

This little bit of code is a calculator of the "golden mean" of a given length of time. For example: given a length of 1 minute and 0 seconds, the answer given will be 0:00:37. See U2's "With or Without You", the Greek Parthenon, the human body, etc.
Substitute your own preferred method of input filtering.
I am just a PHP amateur so don't hate on my code!


Copy this code and paste it in your HTML
  1. <?php
  2. require_once("class.inputfilter_clean.php");
  3. function sec2hms ( $sec, $padHours = false )
  4. {
  5. $hms = "";
  6. $hours = intval( intval( $sec ) / 3600 );
  7. $hms .= ( $padHours )
  8. ? str_pad( $hours, 2, "0", STR_PAD_LEFT ). ':'
  9. : $hours. ':';
  10. $minutes = intval( ( $sec / 60 ) % 60 );
  11. $hms .= str_pad( $minutes, 2, "0", STR_PAD_LEFT ). ':';
  12. $seconds = intval( $sec % 60 );
  13. $hms .= str_pad( $seconds, 2, "0", STR_PAD_LEFT );
  14. return $hms;
  15. }
  16. if ( $_POST["minutes"] or $_POST["seconds"] )
  17. {
  18. $myFilter = new InputFilter( $tags, $attr, $tag_method, $attr_method, $xss_auto );
  19. $minutes = $myFilter->process( $_POST["minutes"] );
  20. $seconds = $myFilter->process( $_POST["seconds"] );
  21. $goodpoint = 0.6180339887 * ( $seconds + ( $minutes * 60 ) );
  22. $answer = sec2hms( $goodpoint );
  23. }
  24. ?>
  25. <html>
  26. <head>
  27. <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  28. <title>
  29. Golden Calculator
  30. </title>
  31. </head>
  32. <body>
  33. <form action="golden.php" method="post">
  34. <p>
  35. Min: <input type="text" name="minutes" />
  36. Sec: <input type="text" name="seconds" />
  37. <input type="submit" />
  38. </p>
  39. </form>
  40. <p>
  41. Answer: <strong><?php echo $answer; ?></strong>
  42. </p>
  43. </body>
  44. </html>

URL: http://ross.uber.name/golden.php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.