Home  >  Article  >  Backend Development  >  PHP addcslashes函数有什么用

PHP addcslashes函数有什么用

PHPz
PHPzOriginal
2016-06-06 20:35:371582browse

PHP addcslashes函数用于返回在指定字符前添加反斜杠的字符串,其语法是“addcslashes(string,characters)”,参数“characters”表示要转义的字符或字符范围。

PHP addcslashes函数有什么用

PHP addcslashes函数有什么用?

定义和用法

addcslashes() 函数返回在指定字符前添加反斜杠的字符串。

注释:addcslashes() 函数对大小写敏感。

注释:对以下字符应用 addcslashes() 时请小心:0(NULL), r(回车), n(换行), f 换页)、t(制表符)以及 v(垂直制表符)。在 PHP 中,\0, \r, \n, \t, \f 以及 \v 是预定义的转义序列。

语法

addcslashes(string,characters)

参数 

string 必需。规定要转义的字符串。

characters 必需。规定要转义的字符或字符范围。

返回值: 返回已转义的字符串。

更多实例

例子 1

向字符串中的特定字符添加反斜杠:

<?php
$str = "Welcome to Shanghai!";
echo $str."<br>";
echo addcslashes($str,&#39;m&#39;)."<br>";
echo addcslashes($str,&#39;H&#39;)."<br>";
?>

更多相关技术知识,请访问PHP中文网

Statement:
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