如果您的示例字符串是典型的,請首先處理單引號和雙引號,這裏使用了heredoc syntax以使字符串安全一起工作
$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);
注意:您還可以使用的preg_replace,但似乎矯枉過正這樣的事情
你可以用'\ S +'作出考慮破折號和引號。 – hjpotter92 2012-04-06 09:25:15