Add space after every 4th character

前端 未结 8 1878
我寻月下人不归
我寻月下人不归 2021-02-11 12:19

I want to add a space to some output after every 4th character until the end of the string. I tried:

$str = $rows[\'value\'];


        
8条回答
  •  梦谈多话
    2021-02-11 12:48

    You can use chunk_split [docs]:

    $str = chunk_split($rows['value'], 4, ' ');
    

    DEMO

    If the length of the string is a multiple of four but you don't want a trailing space, you can pass the result to trim.

提交回复
热议问题