Home > Backend Development > PHP Tutorial > PHP在特殊字符前加斜杠的实现代码_PHP

PHP在特殊字符前加斜杠的实现代码_PHP

WBOY
Release: 2016-06-01 12:14:56
Original
1098 people have browsed it
复制代码 代码如下:
$zongzi = "asdfasdf(asdfasdf?asfdadsf)";
echo $zongzi = quotemeta($zongzi);
echo "
";
$zongzi = stripslashes($zongzi);
echo $zongzi;
?>


PHP quotemeta() 函数
定义和用法
quotemeta() 函数在字符串中某些预定义的字符前添加反斜杠。

这些预定义字符是:

句号 (.)
反斜杠 (\)
加号 (+)
星号 (*)
问号 (?)
方括号 ([])
脱字符号 (^)
美元符号 ($)
圆括号 (())
语法
quotemeta(string)
参数 描述
string 必需。规定要检查的字符串。
提示和注释
提示:该函数可用于转义拥有特殊意义的字符,比如 SQL 中的 ( )、[ ] 以及 *。
复制代码 代码如下:
$str = "Hello world. (can you hear me?)";
echo quotemeta($str);
?>

输出:
Hello world\. \(can you hear me\?\)
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template