Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Test string against simple mask with asterisk *
<?php
class AsteriskMatch
{
/**
* @param string $mask string with asterisk
* @param string $string tested subject
* @return bool
* @throws \Exception
*/
public static function match($mask, $string)
{
$regex = str_replace('\\*', '.*', preg_quote($mask, '/'));
$match = preg_match("/^$regex$/u", $string);
if (is_int($match)) {
return (bool)$match;
} else {
throw new \Exception('Preg error: ' . preg_last_error());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment