String Functions

PHP quotemeta() Function

Topic: PHP String ReferencePrev|Next

Description

The quotemeta() function adds a backslash (\) before every character that is among these:

  • period (.)
  • backslash (\)
  • plus sign (+)
  • asterisk (*)
  • question mark (?)
  • brackets ([])
  • caret (^)
  • dollar sign ($)
  • parenthesis (())

The following table summarizes the technical details of this function.

Return Value: Returns the string with meta characters quoted, or FALSE if empty string is given.
Version: PHP 4+

Syntax

The basic syntax of the quotemeta() function is given with:

quotemeta(string);

The following example shows the quotemeta() function in action.

<?php
// Sample string
$str = "Hello. (Are you there?)";

// Quoting meta characters and print
echo quotemeta($str);
?>

Parameters

The quotemeta() function accepts the following parameters.

Parameter Description
string Required. Specifies the input string.

More Examples

Here're some more examples showing how quotemeta() function actually works:

The following example shows how to quote meta characters in various strings.

<?php
// Sample strings
$str1 = "(2 + 2) * 5 = 20";
$str2 = "Apple iPhone (128GB, Black) [Locked], Price: $499";

// Quoting meta characters and print
echo quotemeta($str1)."<br>";
echo quotemeta($str2);
?>
Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties