PHP - 如何在使用 explode() 函数时排除一个字符?
PHP - How to exclude a character while using explode() function?
<?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);
如果(逗号)',' 出现在(双引号)""
中,我想排除爆炸
您描述的内容听起来更接近 CSV,因此 str_getcsv 可能更适合您的问题。
$text='one,two,"three,four"';
$cols=str_getcsv($text);
print_r($cols);
产生这个输出:
Array
(
[0] => one
[1] => two
[2] => three,four
)
<?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);
如果(逗号)',' 出现在(双引号)""
中,我想排除爆炸您描述的内容听起来更接近 CSV,因此 str_getcsv 可能更适合您的问题。
$text='one,two,"three,four"';
$cols=str_getcsv($text);
print_r($cols);
产生这个输出:
Array
(
[0] => one
[1] => two
[2] => three,four
)