PHP quotemeta() Function
Example
Add backslashes before predefined characters:
Run Example »
Definition and Usage
The quotemeta() function adds backslashes before certain predefined characters in a string.
The predefined characters:
- Period (.)
- Backslash (\)
- Plus sign (+)
- Asterisk (*)
- Question mark (?)
- Square brackets ([])
- Caret (^)
- Dollar sign ($)
- Parentheses (())
**Tip:** This function can be used to escape characters with special meaning, such as ( ), [ ] and * in SQL.
**Note:** This function is binary-safe.
Syntax
quotemeta(
string
)
| Parameters | Description |
|---|---|
| string | Required. Specifies the string to check. |
Technical Details
| Return Value: | Returns the string with quoted metacharacters. |
|---|---|
| PHP Version: | 4+ |
More examples
Example 1
Add backslashes before multiple predefined characters:
"; echo quotemeta($str2).""; echo quotemeta($str3)."
"; echo quotemeta($str4)."
"; echo quotemeta($str5)."
"; ?>
Run Example »
PHP String Reference Manual