First of all, I'm new to development so need a little hand holding.
I've built a simple search field (with suggestions) and send users to a relevant landing page on an array match. I return an error message if the search isn't relevant. However, my code relies on the user clicking a suggestion or typing the whole word in the search field. Therefore, the usability is poor.
The code below will highlight my problem. Ideally, I need to match a field input 'br' to 'bristol' (as per my suggestion to the user). I think the solution is http://php.net/manual/en/function.levenshtein.php but I'm having problems implementing (like I said, I'm new). I would appreciate any guidance.
Thanks heaps for your time!
<?php
$counties = array("Avon",
"Bristol",
"Bedfordshire",
"Berkshire",
"Buckinghamshire"
);
if (in_array(strtolower($_GET["my_input"]), array_map('strtolower', $counties)))
{ header('Location: http://domain.co.uk/county/'.strtolower(str_replace(' ', '-', $_GET['my_input'])));
}
else
{
header('Location: ' . $_SERVER['HTTP_REFERER'] . "?message=tryagain");
exit;
}
?>