0

In one of my webpage instead of showing a very large text from the database, i am showing some part it ending with "[....]Click to read more" using the code:

substr($rowTSD['ts_full_story_p1'],0,150).'[...]'.

It is working fine but as expected it cut shorts a word very often, which does not look good.Is it possible by php or javascript to intelligently truncate a paragraph ahead of a word or after it.Hope you understand my question.

msm
  • 59
  • 7
  • 1
    Find last space and truncate to it's position – u_mulder Nov 24 '16 at 06:41
  • Possible duplicate of [Extract a fixed number of chars from an array, just full words](http://stackoverflow.com/questions/5519890/extract-a-fixed-number-of-chars-from-an-array-just-full-words) – u_mulder Nov 24 '16 at 06:44
  • Or http://stackoverflow.com/questions/79960/how-to-truncate-a-string-in-php-to-the-word-closest-to-a-certain-number-of-chara?rq=1 – u_mulder Nov 24 '16 at 06:45
  • Add a while loop to check whether the 150-th character is a space or not. And then go backwards until a space is found. I do not know javascript/php well enough to code this but that would be my basic idea. – geisterfurz007 Nov 24 '16 at 06:45

0 Answers0