PHP:对输入框中的字符串进行操作(分割,替代等)

本例简单对邮箱地址进行判断,将输入框中的字符“我”替换为字符“本人”

<meta http-equiv="Content-type"  Content="text/html;charset=UTF-8;" />
<!DOCTYPE html>
<style type="text/css">
p{font-family:"方正舒体";font-size:18px;}
div{font-family:"黑体";font-size:18px}
</style>

<form name="f1" method="post" action="">
<p>你的Email地址:<br><input type="email" name="Email" size=31><br>
   你的留言:     <br><textarea name="note" rows=10 cols=30></textarea>
   <br><input type="submit" name="bt1" value="提交"><input type="reset" name="bt2" value="清空">
   </p>
</form>

<?php
    if(isset($_POST['bt1']))
    {
        $Email=$_POST['Email'];
        $note=$_POST['note'];
        if(!$Email||!$note)
            echo"<script>alert('Email地址和留言请填写完整!')</script>";
        else
        {
            $array=explode("@",$Email);
            if(count($array)!=2)
                echo"<script>alert('Email地址格式错误!')</script>";
            else
            {
                $username=$array[0];
                $netname=$array[1];
                if(strstr($username,".") or strstr($username,","))
                    echo"<script>alert('Email地址格式错误!')</script>";
                else
                {
                    $str1=htmlspecialchars("<");
                    $str2=htmlspecialchars(">");
                    $newnote1=str_replace("我","本人",$note);
                    $newnote2=htmlspecialchars($newnote1);
                    echo"<div>";
                    echo"用户".$str1.$username.$str2."你好!&nbsp;";
                    echo"你是".$netname."网友!<br>";
                    echo"<br>你的留言是:<br>&nbsp;&nbsp;&nbsp;".$newnote2."<br>";
                    echo"</div>";
                }
            }
        }
    }
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值