Trim headline to nearest word

后端 未结 6 1826
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-06 19:45

Say for example I have the following code:

My very long title

Another long title

If I wanted to

6条回答
  •  萌比男神i
    2020-12-06 20:33

    using some php and the mighty regular expressions

    function formatHeadline($headline){
        if(preg_match('/(\w+\s+){3}/', $subject, $match)){
            return $match[1]  . '...';
        }
        return $headline;
    }
    

    The same method should be possible in javascript using regex and jquery.

    Jquery also have the ellipsis plugin, you might want to look into it.

提交回复
热议问题