Skip to content

Instantly share code, notes, and snippets.

@ezrabrook
Created May 14, 2014 19:19
Show Gist options
  • Save ezrabrook/777ccb5c888ad5539cad to your computer and use it in GitHub Desktop.
Save ezrabrook/777ccb5c888ad5539cad to your computer and use it in GitHub Desktop.
function hdfs_summarise($paragraph, $limit) {
$textfield = strtok($paragraph, " ");
while ($textfield) {
$text .= " $textfield";
$words++;
if (($words >= $limit) && ((substr($textfield, -1) == "!") || (substr($textfield, -1) == "."))) {
break;
}
$textfield = strtok(" ");
}
return ltrim($text);
}
@ezrabrook
Copy link
Author

Added to the template.php in a drupal theme to truncate the body that it is put on in a theme like

<?php print THEMENAME_summarize($variablefield, 200); ?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment