I'm working on an e-shop. At some point in my code I have to show attributes and descriptions for many products in a single page.Attributes are a table and description can contain simple text and table,li,br tags etc...These which are stored in the database as html encoded string. So in my php file I load them from the db and decode them like this.
$description=html_entity_decode($description_from_db, ENT_QUOTES, 'UTF-8');
$attributes=html_entity_decode($attributes_from_db, ENT_QUOTES, 'UTF-8');
Later on I just do echo $description;
an they are shown properly.
All this HAS TO BE PRINTABLE and here comes the challenge.
When the attributes table and the description are long enough the exceed the printable page height and they get cut in half looking realy ugly. What I want to do is split the $description and $attributes strings and echo them with page breaks between the pieces where neccesary. The problem is that this must be done with respect to the tags inside these strings. I can't for example break the string in the middle of a tr tag.
Is there a way to break these strings maintaining the html elements that they contain intact ? I'm thinking it must be possible since html editors show a warning when a tag has been left unclosed.