Do 22. Mär 2012, 20:30
<?php
include 'head.php';#head einbinden
$PRINT='';
$PRINT.=$head;#head ausgeben
$result = "0";#variablen anlegen
$A=0;# var für 1 textbox
$B=0;# var für 2 textbox
$op="";# var für operator
$check=true;#prüft ob textboxen und op gesetzt
#css mit php
$PRINT.='<style type="text/css"></style>';
# main
$PRINT.= '
<Form Name ="Main" Method ="POST" ACTION = "index.php">
<br /><br /><br />
<input type="text" name="TB0" >
<select name="op">
<option selected>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input type="text" name="TB1" >
<input type="submit" name="SB0" value="=" >
<input type="hidden" name="result" value="" >
<br />
</form>';
#1 textbox prüfen
if (!empty($_POST["TB0"])&&isset($_POST["TB0"]))
{
$A=$_POST["TB0"];
} else {
$check=false;$A='';
}
#2 textbox prüfen
if (!empty($_POST["TB1"])&&isset($_POST["TB1"]))
{
$B=$_POST["TB1"];
} else {
$check=false;$B='';
}
#operator textbox prüfen
if (!empty($_POST["op"])&&isset($_POST["op"]))
{
$op=$_POST["op"];
} else {
$check=false;$op='';
}
#variablen prüfen und auswerten
if($check==true&& !empty($A)&& !empty($B))
{
switch($op)
{
case "+":$result=$A+$B;break;
case "-":$result=$A-$B;break;
case "*":$result=$A*$B;break;
case "/":$result=$A/$B;break;
}
#ausgabe
$PRINT.= '<H1><p><a style="color:blue">'.$A.'</a> <a style="color:crimson">'.$op.'</a> <a style="color:blue">'.$B.'</a> ergibt = <a style="color:green">'.$result.'</a></p></H1>
<script type="text/javascript">
document.Main.result.value = "'.$result.'";
document.Main.result.type="text";
</script>
';
}else{$check=true;}
#footer ausgeben
include 'foter.php';
$PRINT.=$foter;
echo($PRINT);
?>
Do 22. Mär 2012, 20:30
Fr 23. Mär 2012, 07:27
<?php
namespace
{
require_once('./classes/html.php');
$html = new \html\html;
$html -> html_head('Rechenprogrammzeugsdingens, Rechner'); #head einbinden
$result = '0';
# main
?>
<form name = 'main' method = 'post' action = 'index.php'>
<p>
<input type = 'text' name = 'TB0'>
<select name='op'>
<option selected>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input type = 'text' name = 'TB1'>
<button type = 'submit'>Berechne!</button>
<input type = 'hidden' name = 'result' value = ''>
</p>
</form>';
<?php
if(isset($_POST['TB0']) && isset($_POST['TB1']) && isset($_POST['op']) && is_numeric($_POST['TB0']) && is_numeric($_POST['TB1']))
{
// Schnelle Version
if($_POST['op'] === '+') $result = $_POST['TB0'] + $_POST['TB1'];
else if($_POST['op'] === '-') $result = $_POST['TB0'] - $_POST['TB1'];
else if($_POST['op'] === '*') $result = $_POST['TB0'] * $_POST['TB1'];
else if($_POST['op'] === '/') $result = $_POST['TB0'] / $_POST['TB1'];
else $result = 'Unbekannter Fehler';
// Schneckentempo: http://phpbench.com/
/*
switch($_POST['op'])
{
case '+': $result = $_POST['TB0'] + $_POST['TB1']; break;
case '-': $result = $_POST['TB0'] - $_POST['TB1']; break;
case '*': $result = $_POST['TB0'] * $_POST['TB1']; break;
case '/': $result = $_POST['TB0'] / $_POST['TB1']; break;
default: $result = 'Unbekannter Fehler'; break;
}
*/
}
else print 'Bitte korrekt ausfüllen!';
#variablen prüfen und auswerten
#ausgabe
print '<p class = \'blue\'>'.$_POST['TB0'].'</p><p class = \'crimson\'>'.$_POST['op'].'</p><p class = \'blue\'>'.$_POST['TB1'].'</p> ergibt = <p class = \'green\'>'.$result.'</p>';
}
$html -> html_foot();
}
// HTML Namespace & Class
namespace html
{
final class html
{
public function html_head($title, $h2)
{
?>
<!DOCTYPE HTML>
<!-- Ein Volk sollte keine Angst vor der Regierung haben. Die Regierung sollte Angst vor ihrem Volk haben! -->
<html>
<head>
<link rel = 'shortcut icon' type = 'image/x-icon' href = './images/fav.ico'>
<link rel = 'stylesheet' type = 'text/css' href = './styles/style.css'>
<title>Rechner</title>
</head>
<body>
<img class = 'bg' src = './images/bg.jpg' alt = 'Hintergrund'>
<div id = 'kopf'>
<h1><? print $title; ?></h1>
</div>
<div id= 'mitte'>
<div id = 'links'>
<a href = 'index' tabindex = '0'>Rechner</a><br>
<!-- Und weitere Links und so -->
</div>
<div id = 'inhalt'>
<h2><?php print $h2; ?></h2>
<?php
}
public function html_foot()
{
?>
</div>
</div>
</body>
</html>
<?php
}
}
}
/*
CSS file
*{font-size:10pt; font-family:arial, helvetica, sans-serif;}
body{padding:0px; margin:0px; background-color:#000; color:#000; text-align:left;}
img.bg{position:fixed; top:0; left:0; width:100%; height:100%;}
h1{font-size:25pt; font-weight:bold; margin:5px;}
h2{font-size:20pt; font-weight:bold; margin:10px 0px 20px 10px;}
p{margin:0px 10px;}
p.blue{color:00f#;}
p.crimson{color:#f00;}
p.green{color:#0f0;}
button{width:100px; height:40px; margin:10px;}
input[type = text]{background-color:#fff; cursor:text; width:150px; height:15px;}
a{font-weight:bold; text-decoration:none; line-height:20px; margin:5px;}
a:link{color:#666; font-size:10pt;}
a:visited{color:#000;}
a:focus{color:#f00;}
a:hover{color:#f00;}
a:active{color:#fff;}
#kopf{position:relative; line-height:50px; height:50px; margin:25px auto 10px auto; width:80%; background-color:#88d; text-align:center;}
#mitte{position:relative; margin:auto; width:80%;}
#links{position:absolute; margin:auto; width:150px; top:0px; bottom:0px; padding:10px 5px 10px 5px; background-color:#fb6;}
#inhalt{position:relative; min-height:250px; margin:0px 0px 0px 170px; padding:25px 50px; background-color:#ace;}
*/
?>
Fr 23. Mär 2012, 07:57
Fr 23. Mär 2012, 10:01
Fr 23. Mär 2012, 10:06
Fr 23. Mär 2012, 10:34
$start = microtime();
/* codeteil */
echo microtime() - $start;
$m1 = memory_get_usage();
$m1 = memory_get_usage(); #ohne die zweite Variableninitialisierung bekommst nen etwas verfälschten Wert, da $m1 vermutlich erst danach initialisiert wird (also memory_get_usage() -> Erstellung von $m1 (!) -> Zuweisung zu $m1)
/* codeteil */
echo memory_get_usage() - $m1;
Fr 23. Mär 2012, 11:01
Fr 23. Mär 2012, 13:57
Fr 23. Mär 2012, 16:34
Fr 23. Mär 2012, 16:48
Bei iphpbb3.com bekommen Sie ein kostenloses Forum mit vielen tollen Extras
Forum kostenlos einrichten - Hot Topics - Tags
Beliebteste Themen: Erde, Österreich, Wien, USA, NES
Impressum | Datenschutz