php addslashes函数_PHP教程

php中文网
发布: 2016-07-14 10:08:50
原创
1420人浏览过

php addslashes函数最终对应的c函数为:

 
3244 PHPAPI char *php_addslashes_ex(char *str, int length, int *new_length, int should_free, int ignore_sybase TS     RMLS_DC)
3245 {
3246     /* maximum string length, worst case situation */
3247     char *new_str;
3248     char *source, *target;
3249     char *end;
3250     int local_new_length;
3251 
3252     if (!new_length) {
3253         new_length = &local_new_length;
3254     }
3255     if (!str) {
3256         *new_length = 0;
3257         return str;
3258     }
3259     new_str = (char *) safe_emalloc(2, (length ? length : (length = strlen(str))), 1);
3260     source = str;
3261     end = source + length;
3262     target = new_str;
3263 
3264     if (!ignore_sybase && PG(magic_quotes_sybase)) {
3265         while (source
3266             switch (*source) {
3267                 case '':
3268                     *target++ = '\';
3269                     *target++ = '0';
3270                     break;
3271                 case ''':
3272                     *target++ = ''';
3273                     *target++ = ''';
3274                     break;
3275                 default:
3276                     *target++ = *source;
3277                     break;
3278             }
3279             source++;
3280         }
3281     } else {
3282         while (source
3283             switch (*source) {
3284                 case '':
3285                     *target++ = '\';
3286                     *target++ = '0';
3287                     break;
3288                 case ''':
3289                 case '"':
3290                 case '\':
3291                     *target++ = '\';
3292                     /* break is missing *intentionally* */
3293                 default:
3294                     *target++ = *source;
3295                     break;
3296             }
3297 
3298             source++;
3299         }
3300     }
3301 
3302     *target = 0;
3303     *new_length = target - new_str;
3304     if (should_free) {
3305         STR_FREE(str);
3306     }
3307     new_str = (char *) erealloc(new_str, *new_length + 1);
3308     return new_str;
3309 }
从上面看addslashes函数处理的是单字节的字节。
 
但是gbk编码是双字节的。而且5c又可以做双字节的低位。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477745.htmlTechArticlephp addslashes函数最终对应的c函数为: 3244 PHPAPI char *php_addslashes_ex(char *str, int length, int *new_length, int should_free, int ignore_sybase TS RMLS_DC) 3245 { 32...
相关标签:
php
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号