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

PHP
PHP 安全邮件
MySQL 介绍
连接 MySQL
创建 MySQL
MySQL 插入记录
MySQL 选择记录
MySQL Where
MySQL Order By
MySQL 记录更新
MySQL 删除记录
PHP ODBC
XML Expat Parser
XML SimpleXML
PHP 数组参考
PHP Calendar
PHP Date
PHP Directory
PHP Filesystem
PHP FTP
PHP HTTP

PHP 中的 addcslashes() 函数


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

登陆 | 还没注册?