Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML search bar case-sensitive

Tags:

html

php

I have this search bar that when a user inputs a word, the filename in which the search is brought up. To help explain this more clearly, I will add the code that I'm currently dealing with.

HTML

<form method="post" action="submit.php">
            <input name="search" type="text" value="">             
                <button type="submit" name="Submit">
                Submit</button>
                   </form>

submit.php

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

?>

This works perfectly, except for the fact that it is case sensitive and there will also be an error if there's any extra space. For example, if I search for "hello", and the filename is "Hello" or "hello ", the search is dis-functional. Does anyone know how to make this almost ignorant to the case and spaces? Thank you.

like image 246
Mark Smith Avatar asked Apr 18 '26 15:04

Mark Smith


1 Answers

You can trim the POST data and use only lower case letters for your files and transform the 'search' to lowercase.

Something like that : submit.php

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

?>
like image 169
maazza Avatar answered Apr 21 '26 05:04

maazza