Skip to content

Instantly share code, notes, and snippets.

@josuecau
Created January 26, 2015 14:20
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 josuecau/6fe078b5b25cb691b17d to your computer and use it in GitHub Desktop.
Save josuecau/6fe078b5b25cb691b17d to your computer and use it in GitHub Desktop.
<?php
function excerpt($text, $length = 100, $after = '&hellip;')
{
if (mb_strlen($text) > $length) {
$text = preg_replace('/\s+?(\S+)?$/', '', mb_substr($text, 0, $length + 1)) . $after;
}
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment