Created
November 22, 2016 20:54
-
-
Save jhogue/4c922650b696546a6e7d4f88cd1f5430 to your computer and use it in GitHub Desktop.
Truncate a string, leave beginning and end, dot dot dot the middle
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 | |
$content = "A long string of text with an important word at the end"; | |
$posfront = strpos($content, ' ', 10); | |
$first = substr($content, 0, $posfront); | |
$posend = strrpos($content, ' ', -10); | |
$last = substr($content, $posend); | |
//echo $posfront . '<br>'; | |
//echo $first . '<br>'; | |
//echo $last . '<br>'; | |
echo $first . ' … ' . $last; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment