Latest web development tutorials

PHP quotemeta () function

PHP String Reference PHP String Reference

Examples

Before predefined a backslash:

<?php
$str = "Hello world. (can you hear me?)";
echo quotemeta($str);
?>

Running instance »

Definition and Usage

quotemeta () function to add the backslash in the string before some predefined characters.

Predefined characters:

  • period(.)
  • Backslash (\)
  • Plus sign (+)
  • Asterisk(*)
  • question mark(?)
  • Square brackets([])
  • Caret (^)
  • The dollar sign ($)
  • Parentheses (())

Tip: This function can be used to escape characters have special meaning, such as in SQL (), [] and *.

Note: This function is binary safe.


grammar

quotemeta( string )

参数 描述
string 必需。规定要检查的字符串。

technical details

return value: Returns a string quote metacharacters.
PHP version: 4+


More examples

Example 1

Before several predefined a backslash:

<?php
$str1 = "1 + 1 = 2";
$str2 = "1 * 1 = 1";
$str3 = "Could you borrow me 5$?";
$str4 = "Are you not entertained? (I am..)";
$str5 = "The caret [ ^ ] Looks like a hat!";

echo quotemeta($str1)."<br>";
echo quotemeta($str2)."<br>";
echo quotemeta($str3)."<br>";
echo quotemeta($str4)."<br>";
echo quotemeta($str5)."<br>";
?>

Running instance »


PHP String Reference PHP String Reference