0
<?php
$value = 'SKU,Title,LIST PRICE,SELL PRICE,STORE ID,Image,Points,Stock,Product Category,Pricing Attributes "S-030-2324","Salwar Test4",12,10,3,,10,14,"salwar_kameez"';

$val = explode(',',$value);

I want to exclude the exploding if (comma)',' is present inside (double quotes)""

3
  • have you tried to do anything with this so far? Are you saying you want to exclude the values that are quoted? Or you want to ignore commas within strings that are quoted? Commented Feb 26, 2015 at 18:48
  • 1
    This is beyond str_explode. Use CSV functions. Commented Feb 26, 2015 at 18:49
  • 1
    Well you can't do that with a simple string replace. You'll need to use a regular expression match or use @PaulDixon's answer. Commented Feb 26, 2015 at 18:49

1 Answer 1

3

What you're describing sounds closer to CSV, so str_getcsv might be a better fit for your problem.

$text='one,two,"three,four"';
$cols=str_getcsv($text);
print_r($cols);

Produces this output:

Array
(
    [0] => one
    [1] => two
    [2] => three,four
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.