Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.