I am trying to remove the extra whitespaces at the beginning and end of a text generated by ckeditor but not the whtiespaces between the text itself.
I am ending up with many space at beginning and then the actual text.
so I am trying to write a trim function for ckeditor generated text, the traditional trim() not working as the text includes <p></p> and sometimes <br> so I couldn't just write a regex.
Example of the generated text
<p><br><br><br><br><br><br><br><br><br><br><br> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p> </p><p><br><br><br><br><br><br>here text begins</p><p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>another line</p><p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>third line </p><p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><strong>fourth line</strong></p><p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><span class="text-huge"><strong>sdsdsdsdsd</strong></span></p><h2><span class="text-huge"><i><strong><u>sdsdsdsdsdsdsd</u></strong></i></span><br><br><br><br><br><br><span class="text-huge"><i><strong><u>csdsdsdsdsdsds</u></strong></i></span><br><br><br><br><br><br><br><br><br> </h2>
I want to remove every tags until the here text begins but this text might vary might be anything,
any suggestions?