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

PHP
PHP 介绍
PHP 安装
PHP 语法
PHP 变量
PHP操作符
PHP If...Else
PHP Switch
PHP 数组
PHP 循环
PHP 函数
PHP 表单
PHP $_GET
PHP $_POST
PHP Date
PHP Include
PHP 文件处理
PHP 文件上传
PHP Cookies
PHP Sessions
PHP 发送邮件

PHP 中的 addcslashes() 函数


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

登陆 | 还没注册?