\AlphredFilter

Filters arrays to match a query

Summary

Methods
Properties
Constants
Filter()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
remove_all_non_caps()
convert()
filter_item()
No private properties found
N/A

Methods

Filter()

Filter(array  $haystack, string  $needle, string|boolean  $key = false, array  $options = array()) : array

Filters an array based on a query

Passing an empty query ($needle) to this method will simply return the initial array. If you have fold on, then this will fail on characters that cannot be translitered into regular ASCII, so most Asian languages.

The options to be set are:

  • max_results -- the maximum number of results to return (default: false)
  • min_score -- the minimum score to return (0-100) (default: false)
  • return_score -- whether or not to return the score along with the results (default: false)
  • fold -- whether or not to fold diacritical marks, thus making über into uber. (default: true)
  • match_type -- the type of filters to run. (default: MATCH_ALL)

    The match_type is defined as constants, and so you can call them by the flags or by the integer value. Options: Match items that start with the query 1: MATCH_STARTSWITH Match items whose capital letters start with query 2: MATCH_CAPITALS Match items with a component "word" that matches query 4: MATCH_ATOM Match items whose initials (based on atoms) start with query 8: MATCH_INITIALS_STARTSWITH Match items whose initials (based on atoms) contain query 16: MATCH_INITIALS_CONTAIN Combination of MATCH_INITIALS_STARTSWITH and MATCH_INITIALS_CONTAIN 24: MATCH_INITIALS Match items if query is a substring 32: MATCH_SUBSTRING Match items if all characters in query appear in the item in order 64: MATCHALLCHARS Combination of all other ``MATCH*`` constants 127: MATCH_ALL

Parameters

array $haystack

the array of items to filter

string $needle

the search query to filter against

string|boolean $key

the name of the key to filter on if array is associative

array $options

a list of options to configure the filter

Returns

array —

an array of filtered items

remove_all_non_caps()

remove_all_non_caps(string  $string) : string

Removes all non-capital characters and non-digit characters frmo a string

Parameters

string $string

a string to process

Returns

string —

the processed string

convert()

convert(string  $string) : string

Converts and transliterates a string to ascii

Parameters

string $string

a string to transliterate

Returns

string —

the transliterated string

filter_item()

filter_item(string  $value, string  $query, mixed  $match_on, boolean  $fold_diacritics) : array

Runs the filter rules

Parameters

string $value

the value string (haystack)

string $query

the query string (needle)

mixed $match_on

the search flags, so constants or integers

boolean $fold_diacritics

whether or not to transliterate to ascii

Returns

array —

an array that is score and then the rule matched