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初 ...
随机推荐
- Delphi 文件拷贝
function DoCopyDir(sDirName:String;sToDirName:String):Boolean;var hFindFile:Cardinal; t,tfile:String ...
- 传智播客.NET视频学习课件
传智播客.NET视频学习课件访问.NET网站了解更多课程详情http://net.itcast.cn(小提示:为什么本书中超链接打不开?)此套课件是伴随 传智播客.net实况教学视频 (小提示:为什么 ...
- (译)C#参数传递
前言 菜鸟去重复之Sql的问题还没有得到满意的答案.如果哪位大哥有相关的资料解释,能够分享给我,那就太谢谢了. 接触C#一年了,感觉很多东西还是很模糊,像C#中的委托和事件 有些东西看多了不用也还是不 ...
- WPF 卡顿调试经验
1. 问题 最近的一个项目,正常调试情况下,运行一切正常,但是有某个用户登录后,出现界面卡顿2-3mins后,才正常运行. 2.解决问题方法 (1)首先由于是必现问题,就想在vs的工作环境下调试一下, ...
- UWP开发入门(二)——RelativePanel
RelativePanel也是Win10 UWP新增的控件,和上篇提到的SplitView一样在UWP的UI布局起到非常重要的作用.说句实在话,这货其实就是为了UWP的Adaptive UI而特意增加 ...
- 安装php环境
安装xampp 安装zend studio 安装Composer-Setup 安装Z2 ZendFramework-2.4.9 I can install successfully using the ...
- infopath 2007 升级到2013 栏目字段重复生成问题
1. 把Expense Statement.xsn的xsn扩展名改成zip.然后解压后会看到有一个mnifest.xsf. 2. 在vs 2013 中打开它. 3. Search for the fi ...
- kolla 安装
下载 kolla-ansible 和 kolla 源码: git clone http://git.trystack.cn/openstack/kolla-ansible -b stable/quee ...
- 【ocp-12c】最新CUUG OCP-071考试题库(48题)
48.(10-12)choose the best answer View the Exhibit and examine the description for the PRODUCTS and S ...
- CTF中密码学一些基础
本文作者:i春秋签约作家MAX. 凯撒密码作为一种最为古老的对称加密体制,在古罗马的时候都已经很流行,他的基本思想是:通过把字母移动一定的位数来实现加密和解密. 给大家先找两道题,来一起探讨基础密码学 ...