HTML 및 PHP 기본 코딩

<?php

// ========================================================
// HTML 출력
// ========================================================
function put_html() {
    global $g_input_str;

    printf("<!doctype html>\n");
    printf("<html lang=\"ko\">\n");
    printf("  <head>\n");
    printf("    <title>HTML Basic</title>\n");
    printf("    <meta charset=\"utf-8\">\n");
    printf("    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n");
    printf("    <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\n");
    printf("  </head>\n");
    printf("  <body>\n");
    printf("    <h1>HEADING TAG</h1>\n");
    printf("    <p>PARAGRAPH TAG</p>\n");
    printf("    <p>g_input_str:%s</p>\n", $g_input_str);
    printf("    <textarea rows=\"5\" cols=\"40\" disabled>%s</textarea>\n", $g_input_str);
    printf("    <form action=\"/1.php\" method=\"post\">\n");
    printf("    <p><input type=\"text\" name=\"namestr\" placeholder=\"namestr\" style=\"font-size:14pt;height:16px\"></p>\n");
    printf("    <p><textarea name=\"comment\" rows=\"5\" cols=\"40\"></textarea></p>\n");
    printf("    <p><input type=\"submit\" value=\"OK\"></p>\n");
    printf("    </form>\n");
    printf("  </body>\n");
    printf("</html>\n");
}

// ========================================================
// POST 변수값 얻기
// ========================================================
parse_str(file_get_contents("php://input"), $post_vars);
$tmp_str = $post_vars['comment'];

// ========================================================
//  carriage returns 및 TAB 문자 제거
// ========================================================
$tmp_str = str_replace("\t", " ", $tmp_str);
$tmp_str = str_replace("\r", "", $tmp_str);
$g_input_str = str_replace("\n", "<br/>", $tmp_str);

// ========================================================
//  파일로 출력
// ========================================================
$myfile = fopen("/var/www/file.txt", "w") or die("Unable to open file!");
fwrite($myfile, $g_input_str);
fclose($myfile);

// ========================================================
//  HTML 출력
// ========================================================
put_html();

?>

<!doctype html>
<html lang="ko">
  <head>
    <title>HTML Basic</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
  </head>
  <body>
    <h1>HEADING TAG</h1>
    <p>PARAGRAPH TAG</p>
    <p>g_input_str:</p>
    <textarea rows="5" cols="40" disabled></textarea>
    <form action="/1.php" method="post">
    <p><input type="text" name="namestr" placeholder="namestr" style="font-size:14pt;height:16px"></p>
    <p><textarea name="comment" rows="5" cols="40"></textarea></p>
    <p><input type="submit" value="OK"></p>
    </form>
  </body>
</html>
위로 스크롤