これが私の関数、multipleExplodeKeepDelimiters です。また、文字列をさまざまな文に分解し、最後の文字が疑問符であるかどうかを確認することによる、使用方法の例:
function multipleExplodeKeepDelimiters($delimiters, $string) {
$initialArray = explode(chr(1), str_replace($delimiters, chr(1), $string));
$finalArray = array();
foreach($initialArray as $item) {
if(strlen($item) > 0) array_push($finalArray, $item . $string[strpos($string, $item) + strlen($item)]);
}
return $finalArray;
}
$punctuation = array(".", ";", ":", "?", "!");
$string = "I am not a question. How was your day? Thank you, very nice. Why are you asking?";
$sentences = multipleExplodeKeepDelimiters($punctuation, $string);
foreach($sentences as $question) {
if($question[strlen($question)-1] == "?") {
print("'" . $question . "' is a question<br />");
}
}