PHP preg_split。无法为此找到或弄清楚 ex

PHP preg_split. Can't find or figure out ex for this

我确实尝试过,但无法找到或找出以下内容的正则表达式

在PHP工作需要preg_split才能工作

{password=123456, telephone=9452979342}/{Accept=application/json, Authorization=Bearer kadaljdlkadjsdaskdjaskdasdf}

我想要的是将这个字符串拆分成这样的数组:

  1. 中间用'/'分割

    [0] => {password=123456, telephone=9452979342}
    
    [2] => {Accept=application/json, Authorization=Bearer kadaljdlkadjsdaskdjaskdasdf}
    
  2. Select 在 {*}

    之间
    [0] => password=123456, telephone=9452979342
    
    [2] => Accept=application/json, Authorization=Bearer kadaljdlkadjsdaskdjaskdasdf
    

是你想要的吗:

$str = "{password=123456, telephone=9452979342}/{Accept=application/json, Authorization=Bearer kadaljdlkadjsdaskdjaskdasdf}";
preg_match('~\{(.+?)\}/\{(.+?)\}~', $str, $matches);
print_r($matches);

输出:

Array
(
    [0] => {password=123456, telephone=9452979342}/{Accept=application/json, Authorization=Bearer kadaljdlkadjsdaskdjaskdasdf}
    [1] => password=123456, telephone=9452979342
    [2] => Accept=application/json, Authorization=Bearer kadaljdlkadjsdaskdjaskdasdf
)

按照你的方式,你也可以试试下面的方法

$re = '/\}\/\{/m';
$str = '{password=123456, telephone=9452979342}/{Accept=application/json, Authorization=Bearer kadaljdlkadjsdaskdjaskdasdf}';
$arr=preg_split($re,$str);
$cnt=0;
foreach($arr as $values)
 $arr[$cnt++]=preg_replace('/[{}]/','',$values);
 print_r($arr);

run here