Divide a string in N equal parts | Function to print n equal parts of str ; Check if string can be divided in n equal parts ; Calculate the size of parts to find the division point ; Driver Code length od string is 28 ; Print 4 equal parts of the string
< ? php function divideString ( $ str , $ n ) { $ str_size = strlen ( $ str ) ; $ i ; $ part_size ; if ( $ str_size % $ n != 0 ) { echo " Invalid ▁ Input : ▁ String ▁ size " ; echo " ▁ is ▁ not ▁ divisible ▁ by ▁ n " ; return ; } $ part_size = $ str_size / $ n ; for ( $ i = 0 ; $ i < $ str_size ; $ i ++ ) { if ( $ i % $ part_size == 0 ) echo " STRNEWLINE " ; echo $ str [ $ i ] ; } } $ str = " a _ simple _ divide _ string _ quest " ; divideString ( $ str , 4 ) ; ? >