Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jhogue
Created November 22, 2016 20:54
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 jhogue/4c922650b696546a6e7d4f88cd1f5430 to your computer and use it in GitHub Desktop.
Save jhogue/4c922650b696546a6e7d4f88cd1f5430 to your computer and use it in GitHub Desktop.
Truncate a string, leave beginning and end, dot dot dot the middle
<?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 . ' &hellip; ' . $last;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment