Split Long String of HTML Source Between the Two Words or Tags Closest to the Middle
Posted on 2006-11-20
I have string variables containing several hundred characters of HTML source code, and I want to divide them into two lines when they print to a Web page, by inserting a "\n" about halfway through the string -- but only between two words or between two HTML Tags, and only if the string exceeds a certain length.
For example, it should test to see if the string is over 300 characters. If so, it should insert a "\n" close to the middle of the string without breaking up a word, and without breaking up the contents of any HTML tag.
How would this be done?