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.
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";
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With