quotemeta()

quotemeta() — Quote meta characters.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Returns a version of str with a backslash character (\) before every character that is among these: . \ + * ? [ ^ ] ( $ )

Signature

quotemeta(string $string): string

Parameters

ParameterTypeWhat it takes
$stringstringThe input string.

Return value

Returns the string with meta characters quoted. If an empty string is given as string, an empty string is returned.

Example

A runnable snippet:

var_dump(quotemeta('PHP is a popular scripting language. Fast, flexible, and pragmatic.'));

Output:

string(69) "PHP is a popular scripting language\. Fast, flexible, and pragmatic\."

Changelog

VersionChange
8.0.0Returns an empty string, instead of false, when string is empty.

See also

addslashes(), addcslashes(), htmlentities(), htmlspecialchars(), nl2br(), stripslashes(), stripcslashes(), preg_quote()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page quotemeta() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.