Greywacke Posted April 7, 2010 Share Posted April 7, 2010 hi there,i need to check wether a certain string exists within an array of strings. there are two arrays that are checked respectively, with the following bit of php in the getsuppliers function.if $status = 0 it is an active supplier, if &status = 2 it is a prospecting supplier. the following excerpt is from inside an if statement. if (!function_exists('fnmatch')) { function fnmatch($pattern, $string) { for ($op = 0, $npattern = '', $n = 0, $l = strlen($pattern); $n < $l; $n++) { switch ($c = $pattern[$n]) { case '\\': $npattern .= '\\' . @$pattern[++$n]; break; case '.': case '+': case '^': case '$': case '(': case ')': case '{': case '}': case '=': case '!': case '<': case '>': case '|': $npattern .= '\\' . $c; break; case '?': case '*': $npattern .= '.' . $c; break; case '[': case ']': default: $npattern .= $c; if ($c == '[') { $op++; } else if ($c == ']') { if ($op == 0) return false; $op--; } break; } } if ($op != 0) return false; return preg_match('/' . $npattern . '/i', $string); }}function wc_in_array($needle, $haystack) { # this function allows wildcards in the array to be searched foreach ($haystack as $value) { if (true === fnmatch($value, $needle)) { return true; } } return false;} it doesn't seem the replacement fnmatch function accepts * characters as wildcards. could somebody please help!how could i fix this function? 0o i'm guessing to simplify it, to use stristr instead within the fnmatch replacement...i know it is not returning true if the value is found as i get duplicate suppliers in the array. the excerpt at the top is to check if the supplier has not been added yet. Link to comment Share on other sites More sharing options...
Greywacke Posted April 7, 2010 Author Share Posted April 7, 2010 here is the replacement function and code used, still to check if it works: function str_in_array($needle, $haystack) { // this function allows case insensitive strings in the array to be searched foreach ($haystack as $value) { if (stristr($value, $needle)>-1) { return true; } } return false;}// if excerpt!str_in_array(";;;".$row1["bigint_SupplierID"].";;;",$GLOBALS[($status==2)?"mailaddp":"mailadds"]) Link to comment Share on other sites More sharing options...
Greywacke Posted April 7, 2010 Author Share Posted April 7, 2010 it seems to be working perfectly!ISSUE RESOLVED Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.