Add space after every 4th character

前端 未结 8 1885
我寻月下人不归
我寻月下人不归 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:33

    one-liner:

    $yourstring = "1234567890";
    echo implode(" ", str_split($yourstring, 4))." ";
    

    This should give you as output:
    1234 5678 90

    That's all :D

提交回复
热议问题