As topic said, I need a recursive function that split a string if its contain words longer more than (for example) 5 chars.
Example :
if i have the string “aaaaa aaa a aaaa aaaaa” its ok;
if i have the string “aaaaa bbbbbb aa aaaaa” I need to split 1 time (and, for example, add the char # before the first bbbbb and the last b). So the result will be “aaaaa bbbbb#b aa aaaaa”
if i have the string “aaaaa bbbbbbbbbbbbbbbb aa aaaaa” as before; notice that the bold one this time have 16 chars, so i need to split 3 time this time 🙂
Is there any php function already implemented or i need to make it?
Cheers
Using preg_replace :
Notice I replace every set of 5 characters not followed by a space by the set of 5 characters + #. You can obviously replace the # with anything else.