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

PHP
php 无限分类的实现
常用PHP代码
windows下安装配置php视频教程
MySQL数据库结构和数据的导出和导入
PHP实现 IP Whois 查询
PHP5 this,self和parent关键字详解
PHP 安全技巧连载 #1[译]
PHP 安全技巧连载 #2[译]
PHP 安全技巧连载 #3[译]
PHP 安全技巧连载 #4[译]
PHP 安全技巧连载 #5[译]
PHP 安全技巧连载 #6[译]
PHP 安全技巧连载 #7[译]
PHP 安全技巧连载 #8[译]
PHP 安全技巧连载 #9[译]
PHP 安全技巧连载 #10[译]
PHP 安全技巧连载 #11[译]
PHP error_reporting的使用
PHP 安全技巧连载 #12
使用PHP做Linux/Unix守护进程

PHP 中的 addcslashes() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 478 ::
收藏到网摘: 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

登陆 | 还没注册?