开发者

Preg Replace code for json string

I want to replace all sequential commas ,, with {"v":""} for e开发者_C百科xample ,,,,, would also be replaced.

I've tried

preg_replace('/,+/',',{"v":""},', $string);

Though I probably got something wrong. Any help would be appreciated. Thank you.


This should do what you want:

preg_replace('/,{2,}/', ', {"v":""}', $string);

However, a simple regular expression isn't the best tool for this job because it will break as soon as there is a string containing multiple commas.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜