Add space after every 4th character

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

    PHP3 Compatible:

    Try this:

    $strLen = strlen( $str );
    for($i = 0; $i < $strLen; $i += 4){
      echo substr($str, $i, 4) . ' ';
    } 
    unset( $strLen );
    

提交回复
热议问题