Trimming a block of text to the nearest word when a certain character limit is reached?

前端 未结 6 1105
甜味超标
甜味超标 2020-12-12 05:08

Here is the question: How would your trim a block of text to the nearest word when a certain amount of characters have past. I\'m not trying to limit a certain number words

6条回答
  •  被撕碎了的回忆
    2020-12-12 05:59

    Wouldn't it be simpler to concat the strings using a place holder (i.e.: ###PLACEHOLDER###), count the chars of the string minus your place holder, trim it to the right length with substr and then explode by placeholder?

提交回复
热议问题