Hello,

I have a string s1. I want to insert newline character for every 100 Maximum characters. The words should not be split.

example, $s1 = "word1 word2 word3 word4 word5.........wordn";

if the 100th character is in middle of the word then the newline character should be inserted at the end of the previous ending word.

suppose 100th character is o in word3 then the newline character should be inserted after word2.

Can someone help me in this?

i could have used wordwrap, sometimes the number of characters in the words are smaller and larger in different lines it does not look nice.

Thanks