PHP preg_quote() function

Description

preg_quote() takes a string and returns the same string with any special regular expression characters quoted.

Syntax

PHP preg_quote() function has the following syntax.

string preg_quote ( string $str [, string $delimiter = NULL ] )

Parameter

PHP preg_quote() function has the following parameters.

  • str - The input string.
  • delimiter - If the optional delimiter is specified, it will also be escaped.

Example 1


<?PHP
echo preg_quote( "$3.99" );  // Displays "\$3\.99"   
?>

The code above generates the following result.

Example 2

If you want to escape your delimiter character also, pass it as the second argument to preg_quote() :


<?PHP
echo preg_quote( "http://", "/" );  // Displays "http\:\/\/"   
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Development »




Environment
Error
Hash
Include
Locale
Math
Network
Output
Reflection
PHP Regular Expressions