输入特殊字符时出现错误消息 [英] Error message when special characters are entered
本文介绍了输入特殊字符时出现错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Quote:
如何输入特殊字符时显示错误信息,只允许字母和空格
How to show Error message when special characters are entered, only letters and space are allowed
我尝试过:
What I have tried:
<!DOCTYPE html>
<html>
<body>
<?php
if (isset($_POST['txt'])) {
if (!empty($_POST['txt'])){
$veggies = array("Potato", "Cucumber", "Carrot", "Orange", "Green Beans", "onion");
$fruits = array("Apple", "Banana", "orange", "Pineapple", "Grapes", "Watermelon");
$salad = array_merge ($veggies, $fruits);
$Object = $_POST['txt'];
$search = array_filter($salad, function($list) use ($Object) {
return ( stripos($list, $Object) !== FALSE );
});
print_r($search);
}
else {
echo 'Enter Item';
}
}
?>
<form method="POST">
Search item: <input type="text" name="txt" ><br> <br>
<input type="submit">
</form>
</body>
</html>
推荐答案
_POST ['txt'])){
if(!empty (
_POST['txt'])) { if (!empty(
_POST ['txt'])){
_POST['txt'])){
veggies = array(Potato,Cucumber,Carrot,Orange ,青豆,洋葱);
veggies = array("Potato", "Cucumber", "Carrot", "Orange", "Green Beans", "onion");
这篇关于输入特殊字符时出现错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文