Consider using the explode () function wisely. Or better, but longer - a regular expression that will match a word or tag with all the text inside it. You should consider elements inside html tags as indestructible objects. For example, you can write a function that breaks your large paragraph into the following array of entities:
$data = array( array( "count" => 2, "text" => "This is "), array( "count" => 1, "text" => "<b> a </b>"), array( "count" => 2, "text" => " paragraph which"), ... etc. );
Then you should write a loop that will do small paragraphs from the $ data array.
In addition, sometimes you may not be able to make your paragraph exactly 1,500 words long. It can be more or less because you do not have to separate html tags.
source share