PHP之string之addcslashes()函数使用
addcslashes
- (PHP 4, PHP 5, PHP 7)
- addcslashes — Quote string with slashes in a C style
- addcslashes — 以 C 语言风格使用反斜线转义字符串中的字符
Description
string addcslashes (
string $str ,
string $charlist
)
//Returns a string with backslashes before characters that are listed in charlist parameter.
//返回字符串,该字符串在属于参数 charlist 列表中的字符前都加上了反斜线。
Parameters
str
- The string to be escaped.
- 要转义的字符。
charlist
A list of characters to be escaped. If charlist contains characters \n, \r etc., they are converted in C-like style, while other non-alphanumeric characters with ASCII codes lower than 32 and higher than 126 converted to octal representation.
如果 charlist 中包含有 \n,\r 等字符,将以 C 语言风格转换,而其它非字母数字且 ASCII 码低于 32 以及高于 126 的字符均转换成使用八进制表示。
When you define a sequence of characters in the charlist argument make sure that you know what characters come between the characters that you set as the start and end of the range.
当定义 charlist 参数中的字符序列时,需要确实知道介于自己设置的开始及结束范围之内的都是些什么字符。
<?php
echo addcslashes('foo[ ]', 'A..z');
// 输出:\f\o\o\[ \]
// 所有大小写字母均被转义
// ... 但 [\]^_` 以及分隔符、换行符、回车符等也一并被转义了。
- Also, if the first character in a range has a higher ASCII value than the second character in the range, no range will be constructed. Only the start, end and period characters will be escaped. Use the ord() function to find the ASCII value for a character.
- 另外,如果设置范围中的结束字符 ASCII 码高于开始字符,则不会创建范围,只是将开始字符、结束字符以及其间的字符逐个转义。可使用 ord() 函数获取字符的 ASCII 码值。
<?php
echo addcslashes("zoo['.']", 'z..A');
// output: \zoo['\.']
- Be careful if you choose to escape characters 0, a, b, f, n, r, t and v. They will be converted to \0, \a, \b, \f, \n, \r, \t and \v, all of which are predefined escape sequences in C. Many of these sequences are also defined in other C-derived languages, including PHP, meaning that you may not get the desired result if you use the output of addcslashes() to generate code in those languages with these characters defined in charlist.
- 当选择对字符 0,a,b,f,n,r,t 和 v 进行转义时需要小心,它们将被转换成 \0,\a,\b,\f,\n,\r,\t 和 \v。在 PHP 中,只有 \0(NULL),\r(回车符),\n(换行符)和 \t(制表符)是预定义的转义序列, 而在 C 语言中,上述的所有转换后的字符都是预定义的转义序列。
Return Values
- Returns the escaped string.
- 返回转义后的字符。
Example
<?php
/**
* Created by PhpStorm.
* User: zhangrongxiang
* Date: 2018/2/13
* Time: 下午7:31
*/
$str = 'Hello World! \!';
// Hello\ World\!\ \\!
echo addcslashes( $str, ' !' ) . PHP_EOL;
// \H\e\l\l\o \W\o\r\l\d! \\!
echo addcslashes( $str, 'A..z' ) . PHP_EOL;
// Hello World\! \\\!
echo addcslashes( $str, '\!' ) . PHP_EOL;
// Hello World\! \\!
echo addcslashes( $str, '!' ) . PHP_EOL;
$str = '1234567890';
// \1\2\3\4\5\6\7\8\90
echo addcslashes( $str, '1..9' ) . PHP_EOL;
See
All rights reserved
PHP之string之addcslashes()函数使用的更多相关文章
- php addcslashes()函数 语法
php addcslashes()函数 语法 作用:返回在指定字符前添加反斜杠的字符串 语法:addcslashes(string,characters) 参数: 参数 描述 string 必须,规 ...
- PHP addcslashes() 函数
实例 在字符 "W" 前添加反斜杠: <?php 高佣联盟 www.cgewang.com$str = addcslashes("Hello World!" ...
- OC与c混编实现Java的String的hashcode()函数
首先,我不愿意大家需要用到这篇文章里的代码,因为基本上你就是被坑了. 起因:我被Java后台人员坑了一把,他们要对请求的参数增加一个额外的字段,字段的用途是来校验其余的参数是否再传递过程中被篡改或因为 ...
- string类find函数返回值判定
string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...
- C string.h 常用函数
参考:http://womendu.iteye.com/blog/1218155 http://blog.csdn.net/zccst/article/details/4294565 还有一些,忘记了 ...
- c++中string的常用函数说明
string可以说是是字符数组的升级版,使用更加啊方便,不容易出错.本文对string的常用函数进行简单介绍,做到会用即可. string中的常用函数分为四类,即赋值,添加,比较和删除. 一.赋值 1 ...
- C++ string类及其函数的讲解
文章来源于:http://www.cnblogs.com/hailexuexi/archive/2012/02/01/2334183.html C++中string是标准库中一种容器,相当于保存元素类 ...
- PHP之string之explode()函数使用
explode (PHP 4, PHP 5, PHP 7) explode - Split a string by string explode - 使用一个字符串分割另一个字符串 Descripti ...
- C++string类常用函数
C++string类常用函数 string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初 ...
随机推荐
- 学习python的第五天
4.30自我总结 一复习 1.查看数据类型 #数值10的位置 print(di(10)) #数值10的样式 print(type(10)) 2.关于变量的一些补充 a=1 b=1 c=1 #a,b,c ...
- 命令式语言和声明式语言对比——JavaScript实现快速排序为例
什么是命令式编程 (Imperative Programming)? 命令机器如何做事情,强调细节实现 java.c.c++等都属此类. “这些语言的特征在于,写出的代码除了表现出“什么(What)” ...
- Centos7下修复 视频播放器(先 安装VLC视频播放器)
用最新的CentOS7发现没有视频播放器,于是在http://pkgs.org/上查找,发现了nux dextop仓库上有, 于是到他的官网上http://li.nux.ro/repos.html查了 ...
- Robolectric 单元测试中使用 Ressource
单元测试类中: @RunWith(RobolectricGradleTestRunner.class) @Config(constants=BuildConfig.class, sdk = 21) 获 ...
- Neutron 是怎么实现虚拟三层网络的
Neutron 对虚拟三层网络的实现是通过其 L3 Agent (neutron-l3-agent).该 Agent 利用 Linux IP 栈.route 和 iptables 来实现内网内不同网络 ...
- Javascript实例 -- 计时器, 搜索框,selected联动
计时器: <body> <input type="text" id="i1"> <input type="button& ...
- linux进程管理(一)
进程介绍 程序和进程 程序是为了完成某种任务而设计的软件,比如OpenOffice是程序.什么是进程呢?进程就是运行中的程序. 一个运行着的程序,可能有多个进程. 比如自学it网所用的WWW服务器是a ...
- LOJ#6504. 「雅礼集训 2018 Day5」Convex(回滚莫队)
题面 传送门 题解 因为并不强制在线,我们可以考虑莫队 然而莫队的时候有个问题,删除很简单,除去它和前驱后继的贡献即可.但是插入的话却要找到前驱后继再插入,非常麻烦 那么我们把它变成只删除的回滚莫队就 ...
- hadoop-1.2.1-1.x86_64.rpm、jdk-7u45-linux-x64.tar.gz安装(64位)
一, 配置信息 机器是64位,所以操作系统.软件都是64位的. 操作系统:CentOS6.2(64位): Hadoop是hadoop-1.2.1-1.x86_64.rpm: JDK是jdk-7u4 ...
- IE下判断IE版本的语句...[if lte IE 6]……[endif](用户判断IE版本的如果小于6就显示)
<!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> <![endif]--> ...