I currently have <p>{{event.desc}}</p>
which gives the entire description of the event.
Some have very long description, and i only want, say, the first 50 characters.
How can this be achieved?
Try this:
.fifty-chars {
width: 50ch;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
<p class="fifty-chars">Short event description</p>
<p class="fifty-chars">Long long long long long long long long long
long long long long long long long long long long long long long
long event description</p>
text-overflow: ellipsis;
which will give better optical results than a string truncated abruptly.
Dec 12, 2017 at 12:04
in PHP
<?php
if (strlen($myString) > 20) {
echo substr($myString, 0, 20) . '...';
} else {
echo $myString;
}
?>
text-overflow
to cut off the text.