title: PHP Wildcard Search
body: <p>i tried to setup a wildcard search where the user could use % as a wildcard for each single unknown alphanumeric. this search runs in a loop and could happen several 1000 times a minute - thats why i look for the fastest possible code.</p>
  
  <p>so this is what i tinkered - seems to work - but in my eyes looks horrible stupid? as i'm very new to this regex-thing - any idea/response/correction/improvement very welcome :)</p>
  
  <p>is there not a better/cleaner/faster way than my rookie-coding???</p>
  
  <pre><code>$haystack = explode(',', str_replace('%', '.', strtoupper('DEISD, B%W951%, CCA828')));
  
  $needle = strtoupper('BAW951L');
  
  foreach ($haystack as $pattern) {
      preg_match('/^' . trim($pattern) . '$/', $needle) ? $match = 'true' : $match = 'false';
      // just for debug print what it does
      print(preg_match('/' . trim($pattern) . '/', $needle) . PHP_EOL);
      print($match . PHP_EOL);
  }
  </code></pre>