PHP Function Reference

PHP quotemeta() Function



The PHP quotemeta() function returns the string by adding the backslash character (\) before every meta characters. The predefined meta character are:

  • Period (.)
  • Backslash (\)
  • Plus sign (+)
  • Asterisk (*)
  • Question mark (?)
  • Square Brackets ([ ])
  • Caret (^)
  • Dollar sign ($)
  • Parenthesis (( ))
Note: This function can be used to escape the character with special meaning.

Note: This function is binary-safe.

Syntax

quotemeta(string)

Parameters

string Required. Specify the input string.

Return Value

Returns the string with meta characters quoted, or false if an empty string is given as string.

Example:

The example below shows the usage of quotemeta() function.

<?php
$str1 = "10 + 20 = 30";
$str2 = "5 * 10 = 50";
$str3 = "$100 will not be enough for this.";
$str4 = "What is your name?";

echo quotemeta($str1)."\n";
echo quotemeta($str2)."\n";
echo quotemeta($str3)."\n";
echo quotemeta($str4)."\n";
?>

The output of the above code will be:

10 \+ 20 = 30
5 \* 10 = 50
\$100 will not be enough for this\.
What is your name\? 

❮ PHP String Reference