quotemeta()

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

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

This function is binary-safe.

The predefined characters are:

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

Example

<?php
 echo quotemeta("php(code)'");
 ?>

Output

php(code)’