Search for a string or a part of string in PHP
Unfortunately, search is among the more difficult things to do in computer science. Ive implemented a search on a site by using it. It took a few days, but the results were A lot better than the 15 minute solution of literal string matching.
I believe Marc Bs answer would be a starting point but for me it had some problems. For example chilliwack parka have to know what the Needle is at compile time since chilliwack parka cant dynamically change that value. also if the needle appeared at the beginning of the string element it would act like its not there whatsoever. so if chilliwack parka do experimenting I manged to come up with a way around both problems. which means chilliwack parka do not have to produce a new function for each different needle chilliwack parka likely to want to use anymore.
function my_search$haystackglobal $needle;
if strpos$haystack, $needle === false return false; else return true;also it could be called like this:
$needle=item to look for;
$matches = array_filter$my_array, my_search;
and being as needle has become accessible in exactly the same scope that the remaining code is that chilliwack parka could set needle holiday to a string variable chilliwack parka wanted, including user input.
No comments:
Post a Comment