Created
August 12, 2014 19:01
-
-
Save irazasyed/d659a8e0892536193e23 to your computer and use it in GitHub Desktop.
PHP: Wildcard String Match Checker - Laravel 4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Ported from Laravel 4 for external usage. | |
*/ | |
function is($pattern, $value) { | |
if ($pattern == $value) return true; | |
$pattern = preg_quote($pattern, '#'); | |
// Asterisks are translated into zero-or-more regular expression wildcards | |
// to make it convenient to check if the strings starts with the given | |
// pattern such as "library/*", making any string check convenient. | |
$pattern = str_replace('\*', '.*', $pattern).'\z'; | |
return (bool) preg_match('#^'.$pattern.'#', $value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment