preg_quote
Escape regular expression characters
preg_quote()
function adds a backslash before characters with special meanings in regular expressions so that literal characters can be searched.
This function is useful when using user input in regular expressions.
Use preg_quote() to safely use special characters in regular expressions:
<?php $search = preg_quote ( "://" , "/" ) ; $input = 'https://www.gitbox.net/' ; $pattern = "/ $search /" ; if ( preg_match ( $pattern , $input ) ) { echo "The input is a URL." ; } else { echo "The input is not a URL." ; } ?>
Try it yourself