test.php PHPで "hellow world" を表示させる。
<?phpecho "<h1>Hello World</h1>";?>
ren1.php 三角形の面積を計算する。
xxxxxxxxxx<?php$a = 10; //底辺$b = 50; //高さ$s = $a * $b / 2; //三角形の面積echo "面積=" , $s;print "面積=" . $s;?>
ren2.php 台形の面積を計算する。
xxxxxxxxxx<?php$a = 10; //上底$b = 35; //下底$c = 20; //高さ$daikei = ($a + $b) * $c / 2; //台形の面積echo "面積=" , $daikei;// print "面積=" . $daikei;?>
ren3.php if文で点数の優良を判断し表示する。
xxxxxxxxxx<?php$a = 70;if($a > 60){echo "良";}else{echo "良でない";}?>
ren4.php if elseif文で点数の優、良、可、不可を判断し表示する。
xxxxxxxxxx<?php$a = 70;if($a >= 80){echo "優";}else if($a >= 70){echo "良";}else if($a >= 60){echo "可";}else{echo "不可";}?>
ren5.php 季節を設定し、switch文を使い春夏秋冬を判断し表示する。
xxxxxxxxxx<?php$season = 'summer';switch($season){case 'spring';echo '春です';break;case 'summer';echo '夏です';break;case 'autumn';echo '秋です';break;case 'winter';echo '冬です';break;}?>
formtest2.php フォームのデータをまとめて処理する このプログラムはこれを参考に、次のren6.php を作成するために説明した。
x<?phpif(isset($_POST['name']))$name = $_POST['name'];else $name ="(未入力)";/*if(isset($_POST['name']))$name = $_POST['name'];else $name ="(未入力)";*/?><html><head><title>フォームテスト</title></head><body>あなたのお名前は:<?php echo $name ?><br><form method="post" action="formtest2.php">あなたのお名前は?<input type="text" name="name"><input type="submit"></form></body></html>
ren6.php フォームの郵便番号、住所、氏名、性別入力し、 同じプログラム内で表示
xxxxxxxxxx<html><head><title>フォームのデータをまとめて処理する</title></head><body><?php//フォームから送信されたデータを表示するforeach($_POST as $idx => $val){echo "<p>$idx = $val";}?><form method="post" action="<?PHP echo $_SERVER['PHP_SELF']?>"><table><tr><td>郵便番号</td><td><input type="text" name="zip"></td></tr><tr><td>住所</td><td><input type="text" name="address"></td></tr><tr><td>氏名</td><td><input type="text" name="name"></td></tr><tr><td>性別</td><td><input type="text" name="sex"></td></tr><tr><td>電話番号</td><td><input type="tel" name="phon"></td></tr><tr><td><input type="submit" value="送信" name="sub1"></td></tr></form></body></html>
ren7.php フォームで半径を入力し同じプログラム内で面積を計算し表示
xxxxxxxxxx<?phpif(isset($_POST['radius'])){$radius = @$_POST['radius'];$circle = $radius*$radius*3.14;}else $circle = "(未入力)";echo<<<_END<html><head><title>フォームテスト</title></head><body>面積:$circle<br><form method="post" action="ren7.php">半径を入力<input type="text" name="radius"><input type="submit"></form></body></html>_END;?>
ren8.php フォームで上底、下底、高さを入力し同じプログラム内で 台形の面積を計算し表示する。
xxxxxxxxxx<?php$upper = @$_POST['upper'];$bottom = @$_POST['bottom'];$height = @$_POST['height'];$trapezoid = ($upper+$bottom)*$height/2;echo<<<_END<html><head><title>フォームテスト</title></head><body>面積:$trapezoid<br><form method="post" action="ren8.php">上底<input type="text" name="upper"><br>下底<input type="text" name="bottom"><br>高さ<input type="text" name="height"><br><input type="submit"></form></body></html>_END;?>