DelphiのHTML5 Builder で作るPHPファイルは、ブログでうまく使えないので、当分(ずっとかも)やらないことにしました。
そこで、ローカルでPHPを動かしてみることに。
xamppはすでにインストールしてあったので、xamppのコントロールパネルから、Apache の「Start」をクリックして、サーバーを起動しました。

ブラウザから「http://localhost:81/php/calendar.php」と入力し、カレンダーを実行しました。
calender.php のある場所は、xamppをインストールしたフォルダの、「htdocs/php/」です。
すると見たこともないエラーが・・・
カレンダーはちゃんと動くのに。
Notice: Use of undefined constant year - assumed 'year' in ~ Notice: Use of undefined constant mon - assumed 'mon' in ~ Notice: Use of undefined constant mday - assumed 'mday' in ~
次のカッコの中のyearの前後をシングルコーテーションで括ったらエラーが出なくなりました。
$yyyy = $today[year]; $mm = $today[mon]; $dd = $today[mday];
これでローカルでスクリプトを実行する環境が整いました。
後は前へ進むのみですが、前途多難。
ローカルで作成したPHPファイル「calc.php」を、サーバーに転送し、このブログに読み込んでみました。
実行方法は、ボックスに半角で数値を入力し、ラジオボタンで演算を選び「計算」をクリックします。
【ソース】
<form method=post action="">
<table bgcolor="#FFFFFF">
<tr>
<td width="100">数値Aを入力:</td>
<td width="41"><input size="5" type="text" name="num_a">
</td>
<td width="100">数値Bを入力:</td>
<td width="40"><p>
<input size="5" type="text" name="num_b">
</p>
</td>
</tr>
</table>
<table width="400">
<tr>
<td width="50"><label><input type="radio" name="calc" value="tasu">加算</label></td>
<td width="50"><label><input type="radio" name="calc" value="hiku">減算</label></td>
<td width="50"><label><input type="radio" name="calc" value="kakeru">乗算</label></td>
<td width="50"><label><input type="radio" name="calc" value="waru">除算</label></td>
<td width="70"><label><input type="radio" name="calc" value="amari">剰余算</label></td>
</tr>
</table>
<INPUT name="submit2" TYPE="submit" VALUE="計算">
</FORM>
<?php
extract($_POST);
//四則計算の種類(ラジオボタンから取得)
$kind = @$calc;
//半角数値かを判定
if (is_numeric(@$num_a) and is_numeric(@$num_b)) {
//四則計算の種類を判定して計算する
switch ($kind) {
case "tasu":
$ans = @$num_a + @$num_b;
$text = @$num_a."+".@$num_b."= ";
break;
case "hiku":
$ans = @$num_a - @$num_b;
$text = @$num_a."-".@$num_b."= ";
break;
case "kakeru":
$ans = @$num_a * @$num_b;
$text = @$num_a."*".@$num_b."= ";
break;
case "waru":
$ans = @$num_a / @$num_b;
$text = @$num_a."/".@$num_b."= ";
break;
case "amari":
$ans = @$num_a % @$num_b;
$text = @$num_a."%".@$num_b."= ";
break;
}
echo "<table>";
echo "<tr>";
echo "<td>$text $ans </td>";
echo "</tr>";
echo "</table>";
} else {
echo "数値を半角で入力してください。<br>";
}
?>