Skip to content

Instantly share code, notes, and snippets.

@roelven
Created April 19, 2010 12:23
Show Gist options
  • Save roelven/370982 to your computer and use it in GitHub Desktop.
Save roelven/370982 to your computer and use it in GitHub Desktop.
Generic function for nicely cutting of strings
<?php
// Generic function for nicely cutting of strings
// @text = textstring
// @limit = characters to display at end of string (...)
// @end = end at xth character
function wordCut($text, $limit, $end) {
if (strlen($text) > $limit) {
$text = strip_tags($text);
$txt1 = wordwrap($text, $limit, '[cut]');
$txt2 = explode('[cut]', $txt1);
$ourTxt = $txt2[0];
$finalTxt = $ourTxt.$end;
} else {
$finalTxt = $text;
}
return $finalTxt;
};
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment