PHP入门1.6

  • 表单项目
    • htmlspecialchars()函数用来将一些预定义的字符转成HTML实体
      • 预定义字符 (结尾的分号都在中括号里的)
        • &——>[&amp];
        • ” ——>[&quot];
        • ’ ——>[&#039];
        • <——>[&lt];
        • >——>[&gt];
    • trim()函数用于去除用户输入数据中不必要的字符
      • 空格
      • Tab
      • 换行
    • stripslashes()函数去除用户输入数据中的反斜杠[ \ ]
    • $_SERVER[“REQUEST_METHOD”]通过判断是否等于POST来检测表单是否被提交
    • > action = “$_SERVER[“PHP_SELF” 表示表单数据被发送到当前页面
    • >”$_SERVER[“PHP_SELF”]”服务器变量可能被黑客利用,故应使用httpspecialchars()函数来防止被黑客利用。
Example:

    <!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>Hello Php</title>    
    </head>
    <body>
        <?php 
            $user = $email = $sex = $csdn = $content = $checkbox = $school = "";
            $checkboxArray = array("JAVA","Android");
            if($_SERVER["REQUEST_METHOD"] == "POST"){
                $user = input_special($_POST["user"]);
                $email = input_special($_POST["email"]);
                $sex = input_special($_POST["radio"]);
                $csdn = input_special($_POST["CSDN"]);
                $checkboxArray = $_POST["checkbox"];
                $content = input_special($_POST["content"]);
                $school = input_special($_POST["school"]);
            }

            function input_special($date){
                $date = trim($date);
                $date = stripcslashes($date);
                $date = htmlspecialchars($date);
                return $date;
            }
        ?>

        <div class="form" style="float:left;">
            <form name = "form" method = "post" action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
                <p>
                    用户名:<input type = "text" name = "user"/>
                </p>
                <p>
                    用户邮箱:<input type = "text" name = "email"/>
                </p>
                <p>
                    性别:<input name = "radio" type = "radio" value = "男" checked = "true"><input name = "radio" type = "radio" value = "女"></P>
                <p>
                    CSDN地址:<input type = "text" name = "CSDN"/>
                </p>
                <p>
                    简历:<textarea name = "content" rows = "5" cols = "25"></textarea>
                </p>
                <p>
                    学习语言:
                    <input name = "checkbox[]" type = "checkbox" value = "JAVA" checked="true"/>JAVA
                    <input name = "checkbox[]" type = "checkbox" value = "Android"/>Android
                    <input name = "checkbox[]" type = "checkbox" value = "C#"/>C#
                    <input name = "checkbox[]" type = "checkbox" value = "PHP"/>PHP
                    <input name = "checkbox[]" type = "checkbox" value = "HTML"/>HTML
                </p>
                <p>
                    毕业学校:
                    <select size = "1" name = "school">
                        <option value="泉州师范学院">泉州师范学院</option>
                        <option value="泉州大学">泉州大学</option>
                    </select>
                </p>
                <P>
                    <input name = "submit" type = "submit" value = "提交"/>
                </p>
            </form>
        </div>
        <div class="info" style="float:left;">
        <?php
            echo "<h3>提交的表单信息</h3>";
            if($_SERVER["REQUEST_METHOD"] == "POST"){
                echo "<br>";
                echo $user;
                echo "<br>";
                echo $email;
                echo "<br>";
                echo $sex;
                echo "<br>";
                echo $csdn;
                echo "<br>";
                echo $content;
                echo "<br>";
                foreach ($checkboxArray as $value){ 
                            echo $value." "; 
                            } 
                echo "<br>";
                echo $school;
                echo "<br>";
            }
        ?>
        <image src="EngineerZhong.jpg"/>
        </div>
    </body>
</html>

这里写图片描述

更新时间:2016817By:EngineerZhong
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值