My aim is to string an amount of text if larger than 85 characters and only display 85 characters followed by “…”.
However, in some cases it only shows “…” and no text at all. Is there a reason for this? i.e. is this caused by certain characters? (i.e. ; ” etc)?
If so, your guidance would be highly appreciated
My code is:
if ((strlen($row["description"]) > 85) && (strlen($row["description"]) > 1)) {
$whitespaceposition = strpos($row["description"]," ",85);
$description_string = substr($row["description"],0,$whitespaceposition)."...";
}
else if ((strlen($row["description"]) < 85) && (strlen($row["description"]) > 1)) {
$description_string = $row["description"];
}
Thank you all in advance
George
Well, if the length of the description is exactly 85 then it probably won’t display anything.
It may be more reliable to show the whole description, but use these CSS rules to take care of trimming them:
Then the browser takes care of ensuring the text is trimmed and adds
...to the end for you.