The PHP quotemeta is an inbuilt function in PHP. It accepts a string as an input and returns a string with a backslash in front of some characters. In this article, we will discuss the PHP quotemeta Function. Also, we will discuss a few examples of using it.
The pre-defined characters are:
- period (.)
- backslash (\)
- plus sign (+)
- asterisk (*)
- question mark (?)
- brackets ([])
- caret (^)
- dollar sign ($)
- parenthesis (())
Syntax
quotemeta($string)
Parameters
The function accepts only one parameter. The string in which we need to add backslash characters is input to the function.
Return Value
The PHP quotemeta Function returns a string after quoting all metacharacters with a backslash (\).

Examples
Let’s discuss a few examples of using the function.
Example 1: When String Contains Dollar ($), Question Mark (?), and Period (.)
For instance, consider an example with a string containing Dollar ($), Question Mark (?), and Period (.).
<?php $string = 'The $ Value of INR is? Answer.'; echo quotemeta($string);; ?>
The function adds a backslash in front of all the pre-defined characters.
OUTPUT: The \$ Value of INR is\? Answer\.
Example 2: When String Contains Parenthesis (()), and Brackets ([])
Similarly, the function adds backslashes in front of parenthesis and brackets.
<?php $string = 'Cat [Meow], Dog (Bark)'; echo quotemeta($string);; ?>
OUTPUT: Cat \[Meow\], Dog \(Bark\)
Example 3: When the String Contains Asterisk (*), and Plus Sign (+)
Similarly, we can pass a string containing Asterisk (*), and Plus Sign (+).
<?php $string = '1 + (2*2) = 5'; echo quotemeta($string);; ?>
OUTPUT: 1 \+ \(2\*2\) = 5
Conclusion
In conclusion, we discussed the PHP quotemeta Function. You can read more about it on the Official PHP Documentation. Additionally, you can read about more PHP String Functions on Concatly.

Vishesh is currently working as an Intermediate Software Engineer with Orion Health, New Zealand. He graduated with a Masters in Information Technology from the University of Auckland in 2021. With more than 4 years of work experience, his expertise includes Java, Python, Machine Learning, PHP, Databases, Design and Architecture.