Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP preg_quote() Function

PHP preg_quote() Function

PHP Regular Expressions (PCRE)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:

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.

PHP Regular Expressions (PCRE)PHP Regular Expressions (PCRE)