3

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?

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
Sid Jones
  • 55
  • 1
  • 1
  • 10

2 Answers2

5

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>
Pierre François
  • 5,850
  • 1
  • 17
  • 38
  • I added one line of code in the CSS: `text-overflow: ellipsis;` which will give better optical results than a string truncated abruptly. – Pierre François Dec 12 '17 at 12:04
0

in PHP

<?php
if (strlen($myString) > 20) {
echo substr($myString, 0, 20) . '...';
 } else {
echo $myString;
}
?>
Ali Sheykhi
  • 95
  • 11