Question

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!

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top