How to add an ellipsis hyperlink after the first space beyond 170 characters?

后端 未结 4 1605
无人及你
无人及你 2021-01-26 08:44

I have a long text like below:

$postText=\"It is a long established fact that a reader will be distracted by the readable content of a page when looking at its l         


        
4条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-26 09:04

    There is no need to use preg_split you still can trim the characters with substr.

    $postText="It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy.";
    $limit = 170;
    $truncated = substr($postText,0,$limit);
    $truncated .= "...read more";
    var_dump($truncated);
    

    Demo

提交回复
热议问题