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()函数使用的更多相关文章

  1. php addcslashes()函数 语法

    php addcslashes()函数 语法 作用:返回在指定字符前添加反斜杠的字符串 语法:addcslashes(string,characters) 参数: 参数 描述 string  必须,规 ...

  2. PHP addcslashes() 函数

    实例 在字符 "W" 前添加反斜杠: <?php 高佣联盟 www.cgewang.com$str = addcslashes("Hello World!" ...

  3. OC与c混编实现Java的String的hashcode()函数

    首先,我不愿意大家需要用到这篇文章里的代码,因为基本上你就是被坑了. 起因:我被Java后台人员坑了一把,他们要对请求的参数增加一个额外的字段,字段的用途是来校验其余的参数是否再传递过程中被篡改或因为 ...

  4. string类find函数返回值判定

     string类find函数返回值判定 代码示例 #include<iostream> #include<cstring> using namespace std; int m ...

  5. C string.h 常用函数

    参考:http://womendu.iteye.com/blog/1218155 http://blog.csdn.net/zccst/article/details/4294565 还有一些,忘记了 ...

  6. c++中string的常用函数说明

    string可以说是是字符数组的升级版,使用更加啊方便,不容易出错.本文对string的常用函数进行简单介绍,做到会用即可. string中的常用函数分为四类,即赋值,添加,比较和删除. 一.赋值 1 ...

  7. C++ string类及其函数的讲解

    文章来源于:http://www.cnblogs.com/hailexuexi/archive/2012/02/01/2334183.html C++中string是标准库中一种容器,相当于保存元素类 ...

  8. PHP之string之explode()函数使用

    explode (PHP 4, PHP 5, PHP 7) explode - Split a string by string explode - 使用一个字符串分割另一个字符串 Descripti ...

  9. C++string类常用函数

    C++string类常用函数 string类的构造函数:string(const char *s);    //用c字符串s初始化string(int n,char c);     //用n个字符c初 ...

随机推荐

  1. [label][webSites]一个结合Google地图的图片浏览网站

    内容中包含 base64string 图片造成字符过多,拒绝显示

  2. 搭建一个基于CentOS的可视化zookeeper管理工具zkUI实现对zk的可视化管理

    一. zookeeper 可视化工具   JMX => CLRProfile ZKUI => java写的一个可视化的web网站 github中下载 https://github.com/ ...

  3. 【javascript】点击复制内容的实现

    各种站点有很多类似的代码,不过都是拿来即用,连个解释也没有.大概看了一下,现在主要使用的有两种办法: 1.documen.execCommand("Copy")或者window.c ...

  4. NPOI+Json文件解析Excel

    记点笔记,加深印象!最近有个导入Excel工能需要完成,Excel列名是中文的,导入Excel我用的NPOI插件,如果不对Excel做解析,列名有可能会给我带来一些字符方面的麻烦,于是想到了一个比较l ...

  5. 【cocos2d-x 环境配置-Mac配置篇】

    目前我配置的环境需求如下: JDK 1.6 XCode Version 4.6 (4H127) Cocos2d-x 2.2.0  Android Developer  一,下载安装 要配置环境一次性下 ...

  6. Android : M 与 N 的权限管理

    从 M 开始,permission 分为 Normal permission Runtime permission Normal permission 直接在 manifest 里声明就可以用了. a ...

  7. Android Bug BaseExpandableListAdapter, getChildView

    @Override public View getChildView(final int groupPosition, final int childPosition, boolean isLastC ...

  8. Ecliplse转IDEA的学习思路

    很多用户都是先学习了 Eclipse.MyEclipse 再转到 IntelliJ IDEA 的,这里需要先说明的是,在学习 IntelliJ IDEA 过程中,你暂且要放下 Eclipse 下的开发 ...

  9. Android 的文档翻译

    https://www.cnblogs.com/Xiegg/p/3428529.html -------->media codec的文档翻译

  10. 【OCP题库-12c】最新CUUG OCP 071考试题库(72题)

    72.View the exhibit for the structure of the STUDENTand FACULTYtables. STUDENT Name Null? Type ----- ...