Skip to content

Instantly share code, notes, and snippets.

@Elsensee
Last active August 29, 2015 13:59
Show Gist options
  • Save Elsensee/10593380 to your computer and use it in GitHub Desktop.
Save Elsensee/10593380 to your computer and use it in GitHub Desktop.
ticket/10423 function
/**
* Cleans a search string by removing single wildcards from it and replacing multiple spaces with a single one.
*
* @param string $search_string The full search string which should be cleaned.
*
* @return string The cleaned search string without any wildcards and multiple spaces.
*/
function phpbb_clean_search_string($search_string)
{
// This regular expressions matches every single wildcard.
// That means one after a whitespace or the beginning of the string or one before a whitespace or the end of the string.
$search_string = preg_replace('#(?<=^|\s)\*(?=\s|$)#', '', $search_string);
$search_string = trim($search_string);
$search_string = preg_replace('#\s+#u', ' ', $search_string);
return $search_string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment