Skip to content

Instantly share code, notes, and snippets.

@aramk
Created March 19, 2012 12:40
Show Gist options
  • Save aramk/2110543 to your computer and use it in GitHub Desktop.
Save aramk/2110543 to your computer and use it in GitHub Desktop.
// Remove the last unfinished sentence in a paragraph if it contains $min_word_count or less words
// Remove the last unfinished sentence in a paragraph if it contains $min_word_count or less words
function remove_unfinished_sentence($paragraph, $min_word_count = 3, $replace = '.') {
$min_word_count = $min_word_count > 1 ? $min_word_count : 1;
return preg_replace('#(\.\s*([^\s\.]+\s+){0,'.($min_word_count-1).'}([^\s\.]+\s*))$#ms', $replace, $paragraph);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment