I want to explode a variable in a little different way

前端 未结 5 1937
遇见更好的自我
遇见更好的自我 2021-02-04 01:30

I have this variable.

$var = \"A,B,C,D,\'1,2,3,4,5,6\',E,F\";

I want to explode it so that I get the following array.

array(
[0         


        
5条回答
  •  礼貌的吻别
    2021-02-04 01:49

    Simply use preg_match_all with the following regex as follows

    preg_match_all("/(?<=').*(?=')|\w+/",$var,$m);
    print_r($m[0]);
    

    Regex Explanation :

    • (?<=').*(?=') Capture each and every character within '(quotes)
    • |\w+ |(OR) Will grab rest of the characters except ,

    Demo

    Regex

提交回复
热议问题