PHP preg_quote() Function
PHP Regular Expressions (PCRE)
The preg_last_error function escapes regular expression characters.
Syntax
string preg_quote ( string $str [, string $delimiter = NULL ] )
preg_quote() needs the parameter str and adds a backslash before each character in the regular expression syntax. This is typically used when you have some runtime string that needs to be matched as a regular expression.
The special regular expression characters are: . \ + * ? [ ^ ] $ ( ) { } = ! < > | : -
Parameter Description:
-
$str: the input string.
-
$delimiter: if the optional delimiter parameter is specified, it will also be escaped. This is typically used to escape the delimiter used by PCRE functions. / is the most common delimiter.
Return Value
Returns the escaped string.
Example
Example 1
The execution result escapes the special characters $ and /, as shown below:
返回 \$40 for a g3\/400
Replace words in text with italics
" . $word . " " , $textbody ) ; echo $textbody ; ?>The execution result is as follows:
This book is *very* difficult to find.