3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

preferences:
63.21 ms | 402 KiB | 5 Q