拆分CSV,但不拆分仅逗号(PHP)吗? [英] Splitting CSV, but not on comma only (PHP)?
本文介绍了拆分CSV,但不拆分仅逗号(PHP)吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想分割CSV字符串.字符串看起来像这样:
I want to split a CSV string. The string looks like that:
"val1","val2","val3,其他","val4"
如您所见,值中可以有一个逗号(请参阅val3),因此对逗号使用explode无效.
As you see, there can be a comma inside the values (see val3), so using explode on the comma wont work.
我也尝试过:
preg_split('/","/', $myLine)
这是行不通的,否则我该怎么办?
This does not work though, how would I do that otherwise?
感谢您的帮助:)
推荐答案
You can use the built in fgetcsv if your data is in a file,
或 str_getcsv (如果您的数据是字符串)
or str_getcsv if your data is a string
这篇关于拆分CSV,但不拆分仅逗号(PHP)吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文