Skip to content

Instantly share code, notes, and snippets.

@codeachange
Forked from irazasyed/str-helper.php
Created May 31, 2016 10:21
Show Gist options
  • Save codeachange/a0f6013fff57662991b7bdffa2ec357f to your computer and use it in GitHub Desktop.
Save codeachange/a0f6013fff57662991b7bdffa2ec357f to your computer and use it in GitHub Desktop.
PHP: Wildcard String Match Checker - Laravel 4
<?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