开发者

php Parsing A String With Multiple Delimiters [duplicate]

开发者 https://www.devze.com 2023-02-12 23:29 出处:网络
This question already has answers here: 开发者_如何学C json_decode to array (12 answers) Closed 7 months ago.
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

精彩评论

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