Forum Moderators: coopster
Give it a try... I used arrays and substr.
May be someone else has a better solution?
<?php
// YOUR TEXT
$txt="merrychrisdetmastdeoeferthtyhtallmyfriendsandedefamddedeewewily";//EMPTY ARRAY
$txt_array=array();// GET STRING LENGHT
$len=strlen($txt);// WANT TO ADD SPACE AFTER X CHARACTER
$number="5"; // here, 5 character//COUNT FOR LOOP BELOW
$count=$len/$number;//SHOW SOME RESULT
echo 'CALCUL: '.$len.'/'.$number.'='.$count.'<br><br>';//LOOP
$i="0";
while($i<=$count) {
if($i=="0") {$ib="0";} else {$ib=($i*$number)+1;}
$txt_array[$i]=substr($txt,$ib,5);
$i++;}//PRINT ARRAY
print_r ($txt_array);//GET FINAL TEXT
$count_array=count($txt_array)-1; $i="0";
while ($i<=$count_array) {
if ($i=="0") {$txt=$txt_array[$i].' '; } else {$txt .=''.$txt_array[$i].' ';}
$i++;}echo '<br><br><b>RESULT</b><br>'.$txt.'';
?>