Split html code into two equal pieces of content, in PHP or JS

I want to take the content of a website article and create two or more columns of text. The tricky part is that I have to keep the html tags and close them if the cutting is done internally <p></p>

eg.

Example:

<p><span>One two three <strong>four</strong></span> five six</p>

      

Result:

<p><span>One two three<span><p>
<p><span><strong>four</strong> five six</p>

      

So the user will be se

One two three 
four five six

      

+1


a source to share


2 answers


You have to keep track of open tags in the stack data structure. Then, when you reach the split point, you need to close all tags that are on the stack in that exact order. Ditto for opening tags on the next line (in reverse order).



+3


a source


If you are going to use javascript I would suggest http://welcome.totheinter.net/columnizer-jquery-plugin/



0


a source







All Articles