【发布时间】:2021-05-15 16:45:51
【问题描述】:
我有这个字符串:
$sc = '[csvtohtml_create include_rows="1-10"
debug_mode="no" source_type="guess" path="largecsv"
source_files="FL_insurance_sample - Kopia.csv2" csv_delimiter="," ]'
我试图弄清楚如何用空格分隔值。这本身不是问题,但如果空格在引号内,我不希望它被分开。
仔细查看下面的source_files。 (我希望数组中的项目为"FL_insurance_sample - Kopia.csv2")
与:
$args = explode( '=', $sc );
我得到了这个结果:
array (size=11)
0 => string '[csvtohtml_create' (length=17)
1 => string 'include_rows="1-10"' (length=19)
2 => string 'debug_mode="no"' (length=15)
3 => string 'source_type="guess"' (length=19)
4 => string 'path="largecsv"' (length=15)
5 => string 'source_files="FL_insurance_sample' (length=33)
6 => string '-' (length=1)
7 => string 'Kopia.csv2"' (length=11)
8 => string '' (length=0)
9 => string 'csv_delimiter=","' (length=17)
10 => string ']' (length=1)
我想要的结果是:
array (size=11)
0 => string '[csvtohtml_create' (length=17)
1 => string 'include_rows="1-10"' (length=19)
2 => string 'debug_mode="no"' (length=15)
3 => string 'source_type="guess"' (length=19)
4 => string 'path="largecsv"' (length=15)
5 => string 'source_files="FL_insurance_sample - Kopia.csv2"' (length=42)
7 => string 'csv_delimiter=","' (length=17)
8 => string ']' (length=1)
我一直在寻找相同的问题,但我不确定答案是否就是我正在寻找的答案。请让我朝着正确的方向前进。 preg_split 是我需要的吗?
【问题讨论】: