爆炸——有点?
使用 PHP,读取如下字符串: 36,2,"$21,830.00","$18,012.50","$20,764.00","$14,935.00","$13,655.00","$15,820.00","$6,895.00","$4,357.50","$4,944.00"
我要爆炸使用逗号 (,) 作为分隔符,但我意识到有一个问题 - 我的货币值也有逗号!谁能建议一种方法来处理这个问题?我想根据逗号进行爆炸,但如果我在引号内则不会。
谢谢!
Using PHP, reading in a string like the following:
36,2,"$21,830.00","$18,012.50","$20,764.00","$14,935.00","$13,655.00","$15,820.00","$6,895.00","$4,357.50","$4,944.00"
I want to explode using the comma (,) as a delimiter, but I've realized there's a problem- my money values also have commas! Can anyone suggest a way to handle this? I want to explode based on commas, but not if I'm inside quotes.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 str_getcsv 函数。它将允许您指定应该解决您的问题的封闭字符。
编辑:没有意识到这仅适用于 PHP 5.3+,所以可能不适合您(尽管评论有一些可能的解决方法)
Try using str_getcsv function. It will allow you to specify the enclosing character that should solve your problem.
Edit: didn't realize this is only for PHP 5.3+ so might not be an option for you (although the comments have some possible workarounds)