基礎から解る!PHP入門講座 プログラム入門に最適な言語、PHPを学ぼう

基礎から解る!PHP入門講座

プログラム入門に最適な言語、PHPを学ぼう      

    ファイル 13−1

    <?php
    error_reporting(1);
    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html lang="ja"><head>
    <meta http-equiv="Content-type" content="text/html; charset=EUC-JP">
    <meta http-equiv="Content-Style-Type" content="text/css">
    <link rel="stylesheet" href="../style.css">
    <style type="text/css">
    <!--
    .nikki {
    font-size:15px;
    line-height:20px;
    text-align:left;
    width:500px;
    padding:10px;
    margin:0px;
    border-style:solid;
    border-width:1px;
    background-color:#ffffff;
    border-color:#abcdef;}
    //-->
    </style>
    <title>メモ帳</title></head>
    <body><div class="file2">

    <?php
    echo "<form action='13_01_memo.php' method='post'>";
    echo "<table width='500' border='0'><tr><td valign='middle'>";
    echo "<span style='margin:0px;font-size:15px'>メモ帳 : ";
    echo date("Y/m/d") . "</span></td></tr></table>¥n";
    /*---------------------------------------------------------------*/
    echo "<table border='0' width='500'><tr><td>";
    /*----------------------------------------------------月表示-----*/
    echo "<select name='month'>";
    $cnt = 1;
    while ($cnt < 13){
      if($cnt == date(n)){
        echo "<option value='$cnt' selected>".$cnt."月</option>";
      } else {
        echo "<option value='$cnt'>".$cnt."月</option>";
      }
    $cnt++;
    }
    echo "</select>";
    /*----------------------------------------------------日表示-----*/
    echo " <select name='day'>";
    $sday = date(j);
    $op = 1;
    while($op <= 31){
      if($op == $sday){
        echo "<option value='$op' selected>".$op."日</option>¥n";
      } else {
        echo "<option value='$op'>".$op."日</option>¥n";
      }
    $op++;
    }
    echo "</select>";
    /*---------------------------------------------------天気表示-----*/
    echo " <select name='weather'>";
    echo "<option value='快晴'>快晴</option>";
    echo "<option value='晴れ'>晴れ</option>";
    echo "<option value='ほぼ晴れ' selected>ほぼ晴れ</option>";
    echo "<option value='曇り'>曇り</option>";
    echo "<option value='ドン曇り'>ドン曇り</option>";
    echo "<option value='曇り/雨'>曇り/雨</option>";
    echo "<option value='雨'>雨</option>";
    echo "</select>";
    /*---------------------------------------------------温度表示-----*/
    echo " <select name='temp'>";
    $op = -10;
    while($op <= 40){
      if($op == 20){
        echo "<option value='$op 度' selected>".$op."度</option>¥n";
      } else {
        echo "<option value='$op 度'>".$op."度</option>¥n";
      }
    $op++;
    }
    echo "</select></td></tr>";
    echo "<tr><td><textarea name='data' cols='70' rows='5'></textarea></td></tr>";
    echo "<tr><td><input type='submit' name='enter' value='書込'></td></tr></table></form>";
    echo "1つのファイルに書込みができるだけです。毎回上書されます。<br>適当に書き込んでみてください。<br><br>";
    /*--------------------------------------------データ受取*/
    $month = $_POST['month'];
    $day = $_POST['day'];
    $weather = $_POST['weather'];
    $temp = $_POST['temp'];
    $data = $_POST['data'];
    $data = htmlspecialchars($data, ENT_QUOTES);  /*タグを無効化 */
    $enter = $_POST['enter'];
    $data = str_replace("¥n", '<br>', $data);
    $data = str_replace("and", 'and', $data);
    $length = strlen($data);
    $youbimei = array("日曜日","月曜日","火曜日","水曜日","木曜日","金曜日","土曜日");
    $stamp = mktime(0,0,0,$month,$day,$year);
    $yb = date(w,$stamp);
    $youbi = $youbimei[$yb];
    $updir = "memo/data";
    /*--------------------------------------------------ここから書き込み部分*/
    if($enter == "書込" and $data != null){
      if($length < 250){
        $filepointer=fopen("./memo/data", "w+");
          flock($filepointer, LOCK_EX);
            fputs($filepointer, $month."and".$day."and".$youbi."and".$weather."and".$temp."and".$data);
          flock($filepointer, LOCK_UN);
        fclose($filepointer);
      } else {
        echo "250文字以内で記述してください。";
      }
    }
    /*--------------------------------------------------ここから表示部分*/
    $filepointer=fopen("./memo/data", "r");
    $fileline = fgets($filepointer);
      $text = split("and",$fileline);
      echo "<td align='center' rowspan='2' valign='middle' bgcolor='#ffffff'>";
      echo "<div class='nikki'>";
      echo "<b>$text[0]月$text[1]日 $text[2]</b> <font color=blue>$text[3] $text[4]</font><br>";
      echo "$text[5]</div>";
    fclose($filepointer);

    ?>

    </div></body></html>
    2019/5
    SUN MON TUE WED THU FRI SAT
          1 2 3 4
    5 6 7 8 9 10 11
    12 13 14 15 16 17 18
    19 20 21 22 23 24 25
    26 27 28 29 30 31  


     フォクすけ©2006 Mozilla Japan



    制作:基礎から解るPHP入門講座 代表:FREEZE

    Copyright © 2005/2/28 flzPHP.All Rights Riserved