Shorten text without splitting words or breaking html tags

前端 未结 8 1352
粉色の甜心
粉色の甜心 2020-12-28 17:06

I am trying to cut off text after 236 chars without cutting words in half and preserving html tags. This is what I am using right now:

$shortdesc = $_helper-         


        
8条回答
  •  感情败类
    2020-12-28 17:43

    You can take an XML approach and push elements to a string var until the length of the string exceed 236

    example code ?

    for each node // text or tag
      push to the string var
    
      if string length > 236
        break
    
    endfor
    

    for parsing HTML in PHP http://simplehtmldom.sourceforge.net/

提交回复
热议问题