1,'b'=>2,'c'=>'da,=cheng')如果有了1,弄出个2的方法,我"/> 1,'b'=>2,'c'=>'da,=cheng')如果有了1,弄出个2的方法,我">

求个字符串切分正则解决办法

WBOY
Release: 2016-06-13 10:52:45
Original
865 people have browsed it

求个字符串切分正则
$var = "a=1,b=2,c='da,=cheng'";
1、把上面的字符串,切分成$var = array('a=1','b=2','c=da,=cheng')
2、最终目标是 $var = array('a'=>1,'b'=>2,'c'=>'da,=cheng')
如果有了1,弄出个2的方法,我的作法是用字符串分割函数,切割到第一个“=”

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

PHP code
$var = "a=1,b=2,c='da,=cheng'";$arr=preg_split('/,(?=\w)/',$var,-1,PREG_SPLIT_NO_EMPTY);foreach($arr as $v){    $t=explode('=',$v,2);    $ar[$t[0]]=$t[1];}print_r($ar);<div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template