Learn PHP - Learn chapter 2

Using PHP

Forms

Form processing:

  • PHP superglobals: $ _ GET and $ _POST for processing form data (form-data)

    <Form> tag Form

    The action attribute: URL specified form data submission

    method attribute: use when submitting the provisions of the HTTP method (recommended POST)

    <Input> tag form element

    type property: dynamically defined label box type

    <!DOCTYPE html>
    <html>
    <head>
      <title>表单处理</title>
    </head>
    <body>
      <form action="index.php" method="post">
          Name:<input type="text" name="name" />
          E-mail:<input type="text" name="E-mail" />
          <input type="submit" value="Yes" />
      </form>
    </body>
    </html>

    HTML document form data will be submitted to post way to handle php files

  • Likewise, PHP file to accept a form POST HTML page form submission data

    <!DOCTYPE html>
    <html>
    <head>
      <title>php处理表单</title>
    </head>
    <body>
      <?php 
          echo $_POST["name"];
          echo "<br />";
          echo $_POST["E-mail"];
       ?>
    </body>
    </html>

    Similarly, the method can also be changed to get the post method to submit the form to be processed form php file

form validation:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>表单处理</title>
</head>
<body>
    <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
        姓名:
        <input type="text" name="name" />
        <br />
        邮箱:
        <input type="text" name="E-mail" />
        <br />
        网址:
        <input type="text" name="url" />
        <br />
        评论:
        <textarea rows="20px" cols="30px" name="txt"></textarea>
        <br />
        性别:
        <input type="radio" value="男" name="sex" />男
        <input type="radio" value="女" name="sex" />女
        <br />
        <input type="submit" value="Yes" />
    </form>
    <?php 
        function br() {
            echo "<br />";
        }
        echo $_POST["name"] ;
        br();
        echo $_POST["E-mail"];
        br();
        echo $_POST["url"];
        br();
        echo $_POST["txt"];
        br();
        echo $_POST["sex"];
     ?>
</body>
</html>

1567507863801

$ _SERVER [ "PHP_SELF"] variables:

Super global variables, return the currently executing script file name

htmlspecialchars () Method:

Characters into HTML entities

Dates and times:

Gets the date and time: date ()

  • 语法:string date(string format[,int timestamp])
  • Arguments: format display format, timestamp is the timestamp
Parameter Value Explanation
Y Year 4-digit full representation
m The numbers indicate the month with leading 0
d The first day of the month, 2 digits with leading zeros
l (L lowercase) Day of the week, the full text
N The first few that week, a string of 1-7
w The first few days of the week, 0-6
with The first few days of the year
W The first few weeks of the year
H Hour, 24-hour format, with leading zeros
i There are number of minutes leading zeros
s The number of seconds, with leading zeros
The The number of seconds from the Unix epoch to today's
time () function:
  • Returns the timestamp of the total number of seconds of the current time
  • Format: int time (void)
microtime () function:
  • Returns the current time timestamp and microsecond
mktime () function:
  • Ditto

Guess you like

Origin www.cnblogs.com/wangyuyang1016/p/11456065.html