Helpful Information
 
 
Category: Post a PHP snippet
Dotting function

This function takes text and, after a certain number of characters have been shown, it replaces the remaining text with " ...". It is easily customizable.

If you didn't understand what I just said, here's the function's code and an example:

function preView($variable, $maxchars)
{
$dnum = intval($maxchars);
if(strlen($variable) > $dnum)
{
$splitpnt = strpos($variable," ",$dnum);
$var = substr($variable, 0, $splitpnt);
$var .= " ...";
}
elseif(strlen($variable) < $dnum)
{
$var = $variable;
}
return $var;
}
Example and Output:

$variable = 'This is so cool!';
$new_variable = preView($variable, 5);

That would output 'This ...' (quotes excluded) because it goes five characters before it dots the rest.

Disclaimer: I found this script somewhere else, renamed the function, and some of the variables names are changed. ;)










privacy (GDPR)