如何在PHP中拆分此字符串?

I have a string that looks like this:

'word','another word','and a sentence','and more','etc etc'

I need to split this into two strings, divided by the second comma, which shouldn't show in either of the sentences. What complicates things is that here can also be commas inside the various quotes parts of the string.

Can anyone help me?

$a="'word','another word','and a sentence','and more','etc etc'";

//preg_match('{(.*?,[^,]*),(.*)}', $a, $matches);
preg_match('{(.*?[^\\\\]\',.*?[^\\\\]\'),(.*)}', $a, $matches); //UPDATE 
print_r($matches);

DISPLAY:

    Array
(
    [0] => 'word','another word','and a sentence','and more','etc etc'
    [1] => 'word','another word'
    [2] => 'and a sentence','and more','etc etc'
)

This very much looks like CSV syntax, so:

$parsed  = str_getcsv($string, ',', "'");
$string1 = join(',', array_slice($parsed, 0, 2));
$string2 = join(',', array_slice($parsed, 2));

If your PHP version is below 5.3 and hence you don't have str_getcsv, you can replicate this using a virtual file handle to php://temp and fgetcsv.

Alternatively, depending on how difficult your syntax is, strtok can be used for a simple parser. Find the first ', then the next ', then a ,, then a ', then the next ' and you have the first part of the string...

Since you are saying that there can be commas in between quotes .. so preg_split can help you much better than explode

        <?php

                 $string = "'word','another word','and a sentence','and more','etc etc'";
                 $pattern = '%\',\'%';
                 $split = preg_split($pattern,$string);
                 $array1 = array();
                 $array2 = array();
                 foreach($split as $key=>$value)
                 {
                    $value  = trim($value,"'");
                    $value = "'{$value}'";

                    if(($key === 0) || ($key ===1))
                    {
                        $array1[] = $value;
                    }
                    else
                    {
                        $array2[] = $value; 
                    }
                 }

                echo $req_string1 = implode(',',$array1);
                echo "<br>";
                echo $req_string2 = implode(',',$array2);     


             ?>

commas in between quotes

$a="'word','another word','and a sentence','and more','etc etc'";

eval("\$arr =  array($a);");

$text1='';
$text2='';
foreach($arr AS $k=>$v){
    if($k<2){
        $text1.=$text1?',':'';
        $text1.="'{$v}'";
    }else{
        $text2.=$text2?',':'';
        $text2.="'{$v}'";
    }
}
echo $text1;
echo PHP_EOL;
echo $text2;

'word','another word'

'and a sentence','and more','etc etc'