Skip to content

Instantly share code, notes, and snippets.

@travisfont
Created March 28, 2018 15:29
Show Gist options
  • Save travisfont/0b850bb29e2becce18ae814ea0d199f2 to your computer and use it in GitHub Desktop.
Save travisfont/0b850bb29e2becce18ae814ea0d199f2 to your computer and use it in GitHub Desktop.
PHP Search Function to add to eephplib
<?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