Calculate the size of parts to find the division point
$ part_size = $ str_size / $ n ; for ( $ i = 0 ; $ i < $ str_size ; $ i ++ ) { if ( $ i % $ part_size == 0 ) echo " STRNEWLINE " ; echo $ str [ $ i ] ; } }