을 :.와
$string = <<<TEST
Hello World, "Japan and China", Americans, Asians, "Jews and Christians", and semi-catholics, Jehovah's witnesses
TEST;
$safe_string = addslashes($string);//make the string safe to work with
$pieces = explode(",",$safe_string);//break into pieces on comma
$words_and_phrases = array();//initiate new array
foreach($pieces as $piece)://begin working with the pieces
$piece = trim($piece);//a little clean up
if(strpos($piece,'"'))://this is a phrase
$words_and_phrases[] = str_replace('"','',stripslashes($piece));
else://else, these are words
$words = explode(" ",stripslashes($piece));
$words_and_phrases = array_merge($words_and_phrases, $words);
endif;
endforeach;
print_r($words_and_phrases);
참고 작동합니다.
당신은 실제로 같은 str_getcsv 매우 간단하게 수행 할 수 있습니다
이
// replace any comma or space by a singe space
$str = preg_replace('/(,+[ ]+)|([ ]+)/', ' ', $str);
// treat the input as CSV, the delimiters being spaces and enclusures double quotes
print_r(str_getcsv($str, ' ', '"'));
출력 :
Array
(
[0] => Hello
[1] => World
[2] => Japan and China
[3] => Americans
[4] => Asians
[5] => Jews and Christians
[6] => and
[7] => semi-catholics
[8] => Jehovah's
[9] => witnesses
)
당신은 고려 대시 따옴표를 만들기 위해'\의 S +'를 사용할 수 있습니다. – hjpotter92