-1

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)) {
        //...
}
VLAZ
  • 26,331
  • 9
  • 49
  • 67
bhutto54
  • 7
  • 3

1 Answers1

0

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.

sromeu
  • 294
  • 2
  • 7