Think about how you can change and manipulate the generated HTML using server-side PHP code. phpQuery is the ultimate solution that will come to your mind. If you haven't heard about phpQuery, you may be interested in this article since I am going to give you a brief introduction to phpQuery and explain how you can use it in real-world projects.
The tutorial shows you how to generate a simple table with alternating row colors (zebra) and column headers from an array of product information. They also talk a bit about why using something server-side like this is important (over something client-side like jQuery) - how it can make things easier by keeping the "business logic" all in one place, leaving your frontend to do what it does best.