PHP quotemeta() Function

The quotemeta() function adds backslashes in front of some predefined characters in a string.

The predefined characters are:

  • period (.)
  • backslash (\)
  • plus sign (+)
  • asterisk (*)
  • question mark (?)
  • brackets ([])
  • caret (^)
  • dollar sign ($)
  • parenthesis (())
string quotemeta ( string $str )

Returns a version of str with a backslash character (\) before every character that is among these:

. \ + * ? [ ^ ] ( $ )

Tip: This function can be used to escape characters with special meanings, such as ( ), [ ], and * in SQL.

Example -

ParameterDescription
strRequired. Specifies the string to check

Returns the string with meta characters quoted, or FALSE if an empty string is given as str.