转义为CSV [英] Escaping for CSV

查看:78
本文介绍了转义为CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在MySQL数据库中存储一个字符串.这些值稍后将在CSV中使用.如何将字符串转义为CSV安全?我认为我需要转义以下内容:逗号,单引号,双引号.

I need to store a string in a MySQL database. The values will later be used in a CSV. How do I escape the string so that it is CSV-safe? I assume I need to escape the following: comma, single quote, double quote.

PHP的addslashes函数可以:

单引号('),双引号(),反斜杠()和NUL(空字节).

single quote ('), double quote ("), backslash () and NUL (the NULL byte).

所以那行不通.有什么建议吗?我宁愿不尝试创建某种正则表达式解决方案.

So that won't work. Suggestions? I'd rather not try to create some sort of regex solution.

另外,我需要能够逃生.

Also, I need to be able to unescape.

推荐答案

使用 fputcsv() 进行写作,并 fgetcsv() 进行阅读.

Use fputcsv() to write, and fgetcsv() to read.

这篇关于转义为CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆