I'm haveing a little trouble working with a string which I need to insert a substring on certain positions.
Basically I'm trying to create a pagination for a wordpress site by inserting <!--nextpage--> on certain point in a content string. The content string is of various size from page to page and can contain HTML..so I need to insert the substring on a logical point without breaking the html.
My initial thought was to count the words and after x-number of words, search for the nearest closing html tag and insert the substring here.
So for example lets say that we insert the substring after every 700th word. Any help would be greatly appriciated :)