Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php HTML搜索栏区分大小写_Php_Html - Fatal编程技术网

Php HTML搜索栏区分大小写

Php HTML搜索栏区分大小写,php,html,Php,Html,我有一个搜索栏,当用户输入一个单词时,显示搜索的文件名。为了更清楚地解释这一点,我将添加我目前正在处理的代码 HTML 这是完美的,除了它是区分大小写的,如果有额外的空间,也会出现错误。 例如,如果我搜索“hello”,而文件名是“hello”或“hello”,则搜索不起作用。 有人知道如何使这几乎不知道的情况和空间吗?谢谢。您可以修剪帖子数据,在文件中只使用小写字母,并将“搜索”转换为小写 诸如此类: submit.php if (isset($_POST['search'])){

我有一个搜索栏,当用户输入一个单词时,显示搜索的文件名。为了更清楚地解释这一点,我将添加我目前正在处理的代码

HTML

这是完美的,除了它是区分大小写的,如果有额外的空间,也会出现错误。 例如,如果我搜索“hello”,而文件名是“hello”或“hello”,则搜索不起作用。
有人知道如何使这几乎不知道的情况和空间吗?谢谢。

您可以修剪帖子数据,在文件中只使用小写字母,并将“搜索”转换为小写

诸如此类: submit.php

if (isset($_POST['search'])){
              header( 'Location: http://headerLocation/'.$_POST['search'].'.xml' ) ;}
              else {
                  echo "Warning, your request could not be completed";
              }

?>
if (isset($_POST['search'])){
              header( 'Location: http://headerLocation/'.strtolower(trim($_POST['search'])).'.xml' ) ;}
              else {
                  echo "Warning, your request could not be completed";
              }

?>

要避免使用空格,请使用此
使用
strtolower($\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\


当你搜索时,结合使用它应该可以做到以下几点:

   trim(strtolower($searchTerm))
你可以用

$search = strtolower($_POST['search']);
$searchtrim = trim($search);

if (isset($searchtrim)){
              header( 'Location: http://headerLocation/'.$searchtrim.'.xml' ) ;}
              else {
                  echo "Warning, your request could not be completed";
              }

?>

如果您的XML只包含小写字母,那么您可以动态地将
$\u POST['search']
更改为小写字母。PHP是否在字符串上有
toLower()
方法?@tymeJV是strtolower()?这只会避免尾随和/或前导空格。
$search = strtolower($_POST['search']);
$searchtrim = trim($search);

if (isset($searchtrim)){
              header( 'Location: http://headerLocation/'.$searchtrim.'.xml' ) ;}
              else {
                  echo "Warning, your request could not be completed";
              }

?>