所以我希望表单找到用户搜索的内容,然后通过下面的数组返回结果。这可能吗?我自己试着编写php,但我很无能为力。
<form action="result.php" method="post">
<input type="text" name="country" size="30" id="autocomplete-ajax" placeholder="Search for country, timezone or city and hit enter!" maxlength="30">
</form>
<?php
$countries = array(
"AD" => "Andorra",
"AE" => "United Arab Emirates",
"AF" => "Afghanistan",
"AG" => "Antiqua and Barbuda",
"AI" => "Anguilla",
"AL" => "Albania",
"ZZ" => "Unkown or Invalid Region");
if (isset($_POST[$countries[0]])){
echo "<p>Correct!</p>";
}
if (isset($_POST[$countries[1]])){
echo "<p>Correct2</p>";
}
?>
答案 0 :(得分:0)
You could replace the other issets with this - it will check the post values against the array
if (isset($_POST["country"])){
foreach($countries as $k => $c){
if(strtolower($c) == strtolower(trim($_POST["country"]))){
echo "<p>Correct!</p>";
}
}
}