爆炸——有点?

发布于 2024-08-11 09:59:10 字数 243 浏览 1 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半葬歌 2024-08-18 09:59:10

尝试使用 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文