Dateigrösse: 3.74 kb
1 <?php 2 $sys = isset($_POST['system']) ? $_POST['system'] : false; 3 $sys = $sys ? $sys : 2; 4 $sys_js = $sys ? $sys-2 : 0; 5 6 $zzz = isset($_POST['zzz']) && $_POST['zzz']!='' ? $_POST['zzz'] : false; 7 $zzz = preg_replace('/\'/', '', $zzz); 8 $zzz = preg_replace('/ /', '', $zzz); 9 settype($zzz, "double"); 10 //settype($zzz, "int"); 11 $zzz = intval(round($zzz)); 12 13 14 if($_POST['hide']=='ok' && $zzz) 15 { 16 echo '<style type="text/css">input.send{display:none !important;}</style>'; 17 $newSys = powExp($zzz, $sys); 18 $result = '<div class="result"><b>' . number_format($zzz, 0, ".", "'") . '</b> im <b>' . $sys . 'er-System</b> = <b>' . $newSys . '</b>'; 19 $result .= '<div class="weiter"><a href="./?nid=seven" title="nächste Zahl">»»»</a></div>'; 20 $result .= '</div>'; 21 } 22 23 function powExp($zahl, $system) 24 { 25 for($i = 0; $i <= $zahl; $i++) 26 { 27 if($zahl < pow($system, $i)) 28 { 29 $exp = ($i-1); 30 return systemChange($exp, $zahl, $system); 31 } 32 } 33 } 34 35 function systemChange($exp, $zahl, $system) 36 { 37 $result = ''; 38 39 for($i = $exp; $i >= 0; $i--) 40 { 41 if(($zahl / pow($system, $i)) >= 1) 42 { 43 $faktor = floor($zahl / pow($system, $i)); 44 $zahl = ($zahl - ($faktor * pow($system, $i))); 45 $result .= $faktor . ' '; 46 } 47 else 48 { 49 $zahl = $zahl; 50 $result .= '0' . ' '; 51 } 52 } 53 54 return $result; 55 } 56 57 ?> 58 59 60 <style type="text/css"> 61 h1 { font-family:palatino,calibri,verdana,sans-serif; font-weight:bolder; font-size:20pt !important; margin:0; padding-bottom:2em; } 62 .result { background-color:transparent; color:#333; padding:1em; border:1pt solid #333; border-radius:5pt; min-width:25em; box-shadow: 2pt 2pt 4pt crimson; font-family:verdana,calibri,sans-serif; font-size:11pt !important; display:inline-block; } 63 .result .weiter { float:right; font-weight:bold; } 64 .result .weiter a { text-decoration:none; color:#000; padding-left:2em; } 65 .result .weiter a:hover { text-decoration:overline; color:crimson; } 66 .content p { padding:5px 0; font-size:11pt !important; } 67 .content form { font-family:verdana,calibri,sans-serif; font-size:11pt !important; } 68 .content input, select { padding:5pt 5pt !important; border:1pt solid #333; font-family:verdana,calibri,sans-serif; font-size:11pt !important; width:100pt; } 69 .content input.send { padding:5px 15pt; border-radius:3pt; font-size:11pt !important; font-weight:bold; display:inline; } 70 .content input:focus, .content input:hover, 71 .content select:focus, .content select:hover { background-color:#fff; } 72 </style> 73 74 <h1>Zahlensystem-Umrechner</h1> 75 76 <div class="content"> 77 <form method="post" action="./?nid=seven" name="converter"> 78 <p>Deine Zahl im 10er-System:</p> 79 <input type="text" name="zzz" size="10" maxlength="7" value="<?php echo isset($_POST['hide']) ? number_format($zzz, 0, ",", "'") : $zzz; ?>" /> 80 <br> 81 <br> 82 <p>umrechnen ins:</p> 83 <select name="system" size="1"> 84 <option value="2">2er-System</option> 85 <option value="3">3er-System</option> 86 <option value="4">4er-System</option> 87 <option value="5">5er-System</option> 88 <option value="6">6er-System</option> 89 <option value="7">7er-System</option> 90 <option value="8">8er-System</option> 91 <option value="9">9er-System</option> 92 </select> 93 <br> 94 <br> 95 <hr align="left" style="width:28em; color:transparent;" /> 96 <br> 97 <input type="hidden" name="hide" value="ok" /> 98 <input type="submit" name="schicken" value="macht ..." class="send" onfocus="if(this.blur)this.blur();" /> 99 </form> 100 101 <?php 102 echo $result; 103 ?> 104 105 </div> 106 107 <script type="text/javascript"> 108 document.converter.zzz.select(); 109 document.converter.system.selectedIndex=<?php echo $sys_js; ?>; 110 </script> 111 112