Convert substr filter from character count to word count

后端 未结 2 1088
Happy的楠姐
Happy的楠姐 2021-01-19 06:58

I\'m using the getExcerpt() function below to dynamically set the length of a snippet of text. However, my substr method is currently based on character count. I\'d like to

2条回答
  •  庸人自扰
    2021-01-19 07:38

    If you want that your script should not ignore the period and comma and other punctuation symbols then you should adopt this approach.

     function getExcerpt($text)
    {
       $my_excerptLength = 100; 
       $my_array = explode(" ",$text);
       $value = implode(" ",array_slice($my_array,0,$my_excerptLength));
       return 
    
    }
    

    Note : This is just an example.Hope it will help you.Don't forget to vote if it help you.

提交回复
热议问题