Split Strings in Half (Word-Aware) with PHP

前端 未结 7 1584
醉话见心
醉话见心 2020-12-11 02:06

I\'m trying to split strings in half, and it should not split in the middle of a word.

So far I came up with the following which is 99% working :

$te         


        
相关标签:
7条回答
  • 2020-12-11 03:02

    Just change the line:

    $half = (int)ceil(count($words = (count(explode(" ",$text))) / 2);
    

    str_word_count() may not count : or / as word.

    0 讨论(0)
提交回复
热议问题