Current Location: Home> Function Categories> preg_quote

preg_quote

Escape regular expression characters
Name:preg_quote
Category:Regular processing PCRE
Programming Language:php
One-line Description:Escape characters with special meanings in regular expressions by adding backslashes to regular expressions.

Definition and usage

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.

Example

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

Similar Functions
Popular Articles