Created
March 16, 2012 18:52
-
-
Save matthewpizza/2051821 to your computer and use it in GitHub Desktop.
Truncate Text
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 | |
// From: http://css-tricks.com/snippets/php/truncate-string-in-center/ | |
$longString = 'abcdefghijklmnopqrstuvwxyz0123456789z.jpg'; | |
$separator = '/.../'; | |
$separatorlength = strlen($separator) ; | |
$maxlength = 25 - $separatorlength; | |
$start = $maxlength / 2 ; | |
$trunc = strlen($longString) - $maxlength; | |
echo substr_replace($longString, $separator, $start, $trunc); | |
//prints "abcdefghij/.../56789z.jpg" | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment