Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有这样的字符串:
5, "hi all, this is a comma", 'text without comma', 5,'a',',',","
我想将字符串分解成一个数组,但仍然有包含逗号的值(用单引号或双引号括起来)
什么是最快的正则表达式(爆炸在这里不起作用)
我可以使用str_getcsv,但字符串有时用单引号括起来,有时用双引号括起来!需要更聪明的东西
str_getcsv
您可以使用 csv 解析器或preg_split与此模式:
$pattern = '~(?:\'[^\']*\'|"[^"]*"|)\K(,|$)~';