array(   [0] => 'ttt',   [1] => '111'"/> array(   [0] => 'ttt',   [1] => '111'">

Heim >Backend-Entwicklung >PHP-Tutorial > 字符串处置成数组

字符串处置成数组

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 13:07:25864Durchsuche

字符串处理成数组
请教大牛们,如何将该字符串"{SUCESS=[ttt,111],ERROR=[rrr,ggg,vd]}"处理成数组
如下
array(
  'SUCESS' => array(
  [0] => 'ttt',
  [1] => '111'
  ),
  'ERROR'=> array(
  [0] => 'rrr',
  [1] => 'ggg',
  [2] => 'vd'
  )


------解决方案--------------------

PHP code
$s="{SUCESS=[ttt,111],ERROR=[rrr,ggg,vd]}";
preg_replace('/(\w+)=\[(.*?)\]/e','$ar[$1]=explode(",","$2")',$s);
print_r($ar);
/*
Array
(
    [SUCESS] => Array
        (
            [0] => ttt
            [1] => 111
        )

    [ERROR] => Array
        (
            [0] => rrr
            [1] => ggg
            [2] => vd
        )

)
*/ <div class="clear">
                 
              
              
        
            </div>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel: ubuntu装配php-curl扩展 Nächster Artikel: php中本土时区设置