Skip to content

Instantly share code, notes, and snippets.

@evadne
Created August 9, 2010 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evadne/515293 to your computer and use it in GitHub Desktop.
Save evadne/515293 to your computer and use it in GitHub Desktop.
<?php
function arGenerateExcerpt ($incomingText = "", $maximumAllowedLength = 75, $wrapperElementTagName = "p") {
$responseText = "";
$contentInParagraphs = explode("</" . $wrapperElementTagName . ">", $incomingText);
foreach ($contentInParagraphs as $paragraph) {
$responseText .= strip_tags($paragraph, "<p>") . "</" . $wrapperElementTagName . ">";
if ((u8strlen($responseText) + u8strlen($paragraph)) >= $maximumAllowedLength)
break;
}
return strip_tags($responseText);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment