Skip to content

Instantly share code, notes, and snippets.

@Dan0sz
Created October 21, 2018 13:00
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 Dan0sz/2dad6438fb3c97199685b1430f8a6fd2 to your computer and use it in GitHub Desktop.
Save Dan0sz/2dad6438fb3c97199685b1430f8a6fd2 to your computer and use it in GitHub Desktop.
Text-Overflow: Ellipsis with PHP
<?php
$text = 'your text'; // or $yourtext;
$maxPos = 50; // Max. number of characters
if (strlen($text) > $maxPos)
{
$lastPos = ($maxPos - 3) - strlen($text);
$text = substr($text, 0, strrpos($text, ' ', $lastPos)) . '...';
}
echo $text;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment