Is there a way to detect if a variable is a pattern in PHP? I know this is possible in JavaScript since patterns are a variable type however in PHP, patterns are inside of strings.
if (is_pattern($myPattern)) {
//...
}
Is there a way to detect if a variable is a pattern in PHP? I know this is possible in JavaScript since patterns are a variable type however in PHP, patterns are inside of strings.
if (is_pattern($myPattern)) {
//...
}
In PHP there is a function called preg_match that basically does what you stated, it tests a string in search of a pattern/regex.
if (preg_match("/php/i", "php is the best programming language.")) {
echo "A match has been found!";
} else {
echo "No match found.";
}
In that case, preg_match would search for the string "php" inside the test string that you have passed as an argument.