开发者

php Parsing A String With Multiple Delimiters [duplicate]

This question already has answers here: 开发者_如何学C json_decode to array (12 answers) Closed 7 months ago.

I want to parse string in php with multiple delimiters I use this code

$pattern = '/[, ]/';

$array = preg_split( $pattern, $string);

This work fine , but I want to use and "[" and "]" as delimiters!!

How can I include this delimiters in $pattern. I try with $pattern = '/[, []]/'; and $pattern = '/[, ]/'; but error occurred.

Thanks


Escaping the brackets should work.

\[

Related: preg_quote()

Edit: use json_decode() instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜