<?php
function str_is($pattern, $value)
{
$patterns = is_array($pattern) ? $pattern : (array) $pattern;
if (empty($patterns)) {
return false;
}
foreach ($patterns as $pattern) {
// If the given value is an exact match we can of course return true right
// from the beginning. Otherwise, we will translate asterisks and do an
// actual pattern match against the two strings to see if they match.
if ($pattern == $value) {
return true;
}
$pattern = preg_quote($pattern, '#');
var_dump($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);
if (preg_match('#^'.$pattern.'\z#u', $value) === 1) {
return true;
}
}
return false;
}
$result = preg_match('/[a-f0-9]{8}-?[a-f0-9]{4}-?4[a-f0-9]{3}-?[89ab][a-f0-9]{3}-?[a-f0-9]{12}/i', '5d8977f1-8809-47b0-a01d-492373fd81c6');
$resultLaravel = str_is('[a-z]', '5d8977f1');
var_dump($result, $resultLaravel);
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
string(8) "\[a\-z\]"
int(1)
bool(false)