Created
April 19, 2010 12:23
-
-
Save roelven/370982 to your computer and use it in GitHub Desktop.
Generic function for nicely cutting of strings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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