preg_match
Perform regular expression matching
preg_match()
function returns whether a match is found in the string.
Use regular expressions to search for "w3school" in a string with case-insensitive:
<?php $str = "Visit W3School" ; $pattern = "/w3school/i" ; echo preg_match ( $pattern , $str ) ; ?>
Try it yourself
Use PREG_OFFSET_CAPTURE to find the location of the match in the input string:
<?php $str = "Welcome to W3School" ; $pattern = "/w3school/i" ; preg_match ( $pattern , $str , $matches , PREG_OFFSET_CAPTURE ) ; print_r ( $matches ) ; ?>
Try it yourself