: This article mainly introduces the form verification required for php programming every day. if you are interested in the PHP Tutorial, please refer to it. This article explains how to implement php form verification and shares it with you for your reference. the specific content is as follows:
1. PHP form processing
Welcome.html
Welcome. php
Welcome <? Php echo $ _ POST ["name"];?>
Your email address is: <? Php echo $ _ POST ["email"];?>
2. PHP form verification complete instance
<? Php // define the variable and set it to null $ nameErr = $ emailErr = $ websiteErr = ""; $ name = $ email = $ website = ""; if ($ _ SERVER ["REQUEST_METHOD"] = "POST") {if (empty ($ _ POST ["name"]) {$ nameErr = "name is required";} else {$ name = test_input ($ _ POST ["name"]); // check whether the name contains letters and blank characters // The preg_match () function retrieves the string mode. if the mode exists, true is returned; otherwise, false is returned. If (! Preg_match ("/^ [a-zA-Z] * $/", $ name) {$ nameErr = "only letters and spaces are allowed ";}} if (empty ($ _ POST ["email"]) {$ emailErr = "email is required ";} else {$ email = test_input ($ _ POST ["email"]); // check whether the email address syntax is valid if (! Preg_match ("/([\ w \-] + \ @ [\ w \-] + \. [\ w \-] +)/", $ email) {$ emailErr =" invalid email format ";}} if (empty ($ _ POST ["website"]) {$ website = "";} else {$ website = test_input ($ _ POST ["website"]); // check whether the URL address syntax is valid (the regular expression also allows the slash in the URL) if (! Preg_match ("/\ B (? :(?: Https? | Ftp): \ // | www \.) [-a-z0-9 + @ # \/%? = ~ _ |! :,.;] * [-A-z0-9 + @ # \/% = ~ _ |]/I ", $ website) {$ websiteErr =" invalid URL ";}} function test_input ($ data) {// remove unnecessary characters (extra spaces, tabs, and line breaks) from user input data $ data = trim ($ data ); // delete the backslash (\) $ data = stripslashes ($ data) in user input data; // Convert Special characters into HTML entities $ data = htmlspecialchars ($ data ); return $ data ;}?> PHP verification instance* Required fields
<? Phpecho "your input:"; echo $ name; echo"
"; Echo $ email; echo"
"; Echo $ website; echo"
";?>
I hope this article will help you learn php programming.
The above describes the forms that php programming requires every day, including the content, hope to be helpful to friends who are interested in PHP tutorials.