quotemeta() 函数在字符串中某些预定义的字符前添加反斜杠。
预定义的字符:(预定义字符比addslashes() 函数多)
•句号(.)
•反斜杠()
•加号(+)
•星号(*)
•问号(?)
•方括号([])
•脱字号(^)
•美元符号($)
•圆括号(())
提示:该函数可用于转义拥有特殊意义的字符,比如 SQL 中的 ( )、[ ] 以及 * 。
注释:该函数是二进制安全的。
语法
quotemeta(string)
string必需。规定要检查的字符串。
$str1 = "1 + 1 = 2";
$str2 = "1 * 1 = 1";
$str3 = "Could you borrow me 5$?";
$str4 = "Are you not e&";
$str5 = "The caret [ ^ ] Looks like a hat!";
echo quotemeta($str1)."
"; // 1 \+ 1 = 2
echo quotemeta($str2)."
"; // 1 \* 1 = 1
echo quotemeta($str3)."
"; // Could you borrow me 5\$\?
echo quotemeta($str4)."
"; // Are you not e&
echo quotemeta($str5)."
"; // The caret \[ \^ \] Looks like a hat!
?>