我有这个搜索栏,当用户输入一个单词时,会出现搜索的文件名.为了更清楚地解释这一点,我将添加我目前正在处理的代码.
HTML
<form method="post" action="submit.php">
<input name="search" type="text" value="">
<button type="submit" name="Submit">
Submit</button>
</form>
Run Code Online (Sandbox Code Playgroud)
submit.php
if (isset($_POST['search'])){
header( 'Location: http://headerLocation/'.$_POST['search'].'.xml' ) ;}
else {
echo "Warning, your request could not be completed";
}
?>
Run Code Online (Sandbox Code Playgroud)
这种方法非常有效,除了它区分大小写并且如果有任何额外空间也会出错.例如,如果我搜索"hello",并且文件名为"Hello"或"hello",则搜索将失效.有谁知道如何使这个几乎无知的案件和空间?谢谢.
您可以修剪POST数据并仅为文件使用小写字母,并将"搜索"转换为小写.
像这样的东西:submit.php
if (isset($_POST['search'])){
header( 'Location: http://headerLocation/'.strtolower(trim($_POST['search'])).'.xml' ) ;}
else {
echo "Warning, your request could not be completed";
}
?>
Run Code Online (Sandbox Code Playgroud)