Created
March 28, 2018 15:29
-
-
Save travisfont/0b850bb29e2becce18ae814ea0d199f2 to your computer and use it in GitHub Desktop.
PHP Search Function to add to eephplib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function search_string_allocator($search_string, $safe_length = 3) | |
{ | |
$search_string = strtolower(trim($search_string)); | |
if (strlen($search_string) >= $safe_length) | |
{ | |
$removals = array | |
( | |
'~', '~', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '_', '+', '=', | |
',', '.', '?', '/', ':', ";", '"', '\'', '[', '{', ']', '}', '|', '\\' | |
); | |
$search_string = str_replace($removals, ' ', $search_string); | |
$search_keywords = explode(' ', $search_string); | |
$keywords = array_filter($search_keywords, function ($data) use ($safe_length) | |
{ | |
if (strlen($data) >= $safe_length) | |
{ | |
return $data; | |
} | |
}); | |
return (array) array_values($keywords); | |
} | |
} | |
// ?q=this%20is%20my%20name.is%20cool%20-%20name-caller | |
/* | |
Array | |
( | |
[0] => this | |
[1] => name | |
[2] => cool | |
[3] => name | |
[4] => caller | |
) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment