当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > addcslashes() 函数

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 中的 addcslashes() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 477 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The addcslashes() function returns a string with backslashes in front of the specified characters.
addcslashes()函数的作用是:像 C 那样使用反斜线转义字符串中的字符。

Syntax
语法

addcslashes(string,characters)

 

Parameter参数 Description描述
string Required. Specifies the string to check
必要参数。指定字符串对象
characters Required. Specifies the characters or range of characters to be affected by addcslashes()
必要参数。指定需要通过addcslashes()函数执行转义操作的字符串中的字符

 


Tips and Notes
注意点

Note: Be careful using addcslashes() on 0, r, n and t. In PHP, \0, \r, \n and \t are predefined escape sequences.
注意:在这里,你需要特别注意addcslashes()函数中关于0, r, n 和 t的用法;在PHP中,\0, \r, \n 和 \t是预先定义的转义序列。


Example 1
案例1

In this example we will add backslashes to certain characters in a string:
在下面的案例中,我们给字符串中指定的字符加上了反斜线“\”:

<?php
$str = "Hello, my name is Kai Jim.";
echo $str."<br />";
echo addcslashes($str,'m')."<br />";
echo addcslashes($str,'K')."<br />";
?>

The output of the code above will be:
上述代码将输出下面的结果:

Hello, my name is Kai Jim.
Hello, \my na\me is Kai Ji\m.
Hello, my name is \Kai Jim.

 


Example 2
案例2

In this example we will add backslashes to a range of characters in a string:
在下面的案例中,我们给字符串中指定的一组字符串加上了反斜线“”:

<?php
$str = "Hello, my name is Kai Jim.";
echo $str."<br />";
echo addcslashes($str,'A..Z')."<br />";
echo addcslashes($str,'a..z')."<br />";
echo addcslashes($str,'a..h');
?>

The output of the code above will be:
上述代码将输出下面的结果:

Hello, my name is Kai Jim.
\Hello, my name is \Kai \Jim.
H\e\l\l\o, \m\y \n\a\m\e \i\s K\a\i J\i\m.
H\ello, my n\am\e is K\ai Jim.

 

评论 (0) All

登陆 | 还没注册?