Add backslashes in front of the predefined characters:
<?php
$str = "Hello world. (can you hear me?)";
echo quotemeta($str);
?>
Try it Yourself »
The quotemeta() function adds backslashes in front of some predefined characters in a string.
The predefined characters are:
Tip: This function can be used to escape characters with special meanings, such as ( ), [ ], and * in SQL.
Note: This function is binary-safe.
quotemeta(
string)
Parameter | Description |
---|---|
string | Required. Specifies the string to check |
Return Value: | Returns the string with meta characters quoted |
---|---|
PHP Version: | 4+ |
Add backslashes in front of many predefined characters:
<?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>";
?>
Try it Yourself »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!