The quotemeta Function
The quotemeta
function adds a backslash before each special character in a string.
The following characters are escaped: .
\
+
*
?
[
^
]
(
$
)
.
The function accepts one parameter - the string to process.
Syntax
quotemeta(string);
Example
Escaping special characters in a simple string:
<?php
echo quotemeta('Hello.world (test)');
?>
Code execution result:
'Hello\.world \(test\)'
Example
Escaping a string containing multiple special characters:
<?php
echo quotemeta('1+1=2? [maybe]');
?>
Code execution result:
'1\+1\=2\? \[maybe\]'
Example
Processing a string without special characters:
<?php
echo quotemeta('simple text');
?>
Code execution result:
'simple text'
See Also
-
the
addslashes
function,
which escapes a string with slashes -
the
preg_quote
function,
which escapes characters in regular expressions