The quotemeta() function adds backslashes in front of some predefined characters in a string.
The predefined characters are:
This function can be used to escape characters in SQL.
PHP quotemeta() Function has the following syntax
quotemeta(string)
Parameter | Is Required | Description |
---|---|---|
string | Required. | String to check |
PHP quotemeta() Function return the string with meta characters quoted.
Add backslashes in front of many predefined characters:
<?php//from w ww .j av a 2s .c o m
$str = "Hello world. (from java2s.com?)";
echo quotemeta($str);
$str1 = "1 + 1 = 2";
$str2 = "1 * 1 = 1";
$str3 = "5$?";
$str4 = "java2s.com$?(...)";
$str5 = "^";
echo quotemeta($str1)."\n";
echo quotemeta($str2)."\n";
echo quotemeta($str3)."\n";
echo quotemeta($str4)."\n";
echo quotemeta($str5)."\n";
?>
The code above generates the following result.