我想重写搜索选项的网址...目前我的搜索选项正常工作..但我想自定义网址和 这是我的html脚本
<form name="search2" method="post" action="my-city.php">
<select name="countryname">
<option value="usa">usa</option>
<option value="aus">aus</option>
</select>
<select name="num">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select name="day">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="submit" value="search"/>
目前的结果: https://mydomain.com/ezhil/mysite/code/my-city.php
预期结果(例如,如果我选择countryname=usa
,num=1
,day=2
网址应该是这样的):
https://mydomain.com/ezhil/mysite/code/my-city/usa/1/2
答案 0 :(得分:0)
您可以在my-city.php
的顶部有以下内容:
<?php
if(array_key_exists("countryname",$_POST) and array_key_exists("num",$_POST) and array_key_exists("day",$_POST))
{
preg_match("/^([a-z]+)$/",$_POST["countryname"],$countryname);
$num = intval($_POST["num"]);
$day = intval($_POST["day"]);
if($contryname[1] != "" and $num > 0 and day > 0)
Header("Location: http://mydomain.com/ezhil/mysite/code/my-city/".$countryname[1]."/".$num."/".$day);
}
?>
另外,您需要修复html代码,如下所示:
<form name="search2" method="post" action="my-city.php">
<select name="countryname">
<option value="usa">usa</option>
<option value="aus">aus</option>
</select>
<select name="num">
<option value="1">1</option>
<option value="2">2</option>
</select>
<select name="day">
<option value="1">1</option>
<option value="2">2</option>
</select>
<input type="submit" value="search"/>