Check out Half-Life Re-imagined competition results!
Check out Skewing textures in Hammer, our newest tutorial!
Welcome, timadam, our newest member!
Someone asked how I did the filtering of articles by a search term. This is the generic function that I use to determine if a block of text does or does not meet the search requirements. It is perhaps not the most elegant code, but it does what I need it to. :)
The $searchable variable is the block of text you want to search through. $search_term is one or more words that are being searched for in the searchable text, and $search_type is one of either "phrase", "all words", or "any words" -- this is used to determine how the search term should be treated if it is more than one word. Some of the code explained:
The above line determines whether the search term, as a complete phrase, is present in the searchable text. It returns TRUE if the string contained in $search_term is found within the $searchable string.
The above block of code breaks the specified search term into an array of individual words, then checks to see that each string element of that array is present in the searchable text. If one of the elements is ever not found, the function immediately returns a FALSE value, otherwise it cycles through all of the elements and then returns TRUE.
This block is very similar to the block of code above it, except for one key difference: it's checking to see if any of the search words exist in the searchable text. The first time a word is found, the function immediately returns a TRUE value, otherwise it cycles through all of the elements and then returns FALSE. One change I should probably make to the above code is to change any instance of multiple spaces in the $search_term string to single spaces. Hope this is of help to someone. :) |