本文實例講述了PHP簡單處理表單輸入的特殊字符的方法。分享給大家供大家參考,具體如下:
<html> <body> <?php if ($_POST['submitted'] == "yes"){ $yourname = $_POST['yourname']; $yourname = trim ($yourname); $yourname = strip_tags ($yourname); $yourname = htmlspecialchars ($yourname); $yourname = addslashes ($yourname); echo $yourname . "<br />"; ?><a href="index.php">Try Again</a><?php } if ($_POST['submitted'] != "yes"){ ?> <form action="index.php" method="post"> <p>Example:</p> <input type="hidden" name="submitted" value="yes" /> Your Name: <input type="text" name="yourname" maxlength="150" /><br /> <input type="submit" value="Submit" /> </form> <?php } ?> </div> </body> </html>
更多關於PHP相關內容感興趣的讀者可查看本站專題:《php字符串(string)用法總結》、《PHP運算與運算符用法總結》、《PHP基本語法入門教程》及《php防止SQL注入方法總結》
希望本文所述對大家PHP程序設計有所幫助。