php domdocument vs php-html-generator vs another php html generator class


I want to use php to standard html output from several ppl.

I was thinking of using a class similar to php-html-generator found on git ( ). Essentially this class would be slightly modified to create bootstrap 4 elements without having to set attributes continually.

Or is it a better idea to use the built-in domdocument class?

J NUnicorn wranglerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
What would be your motivation for using this?

All I can see is it adds additional processing time and takes away the ability to see the structure of your document.

I can understand code that emits components (blocks of HTML and code that perform a specific task) but I don't understand why you would want to do this at the element level.

Maybe I am not understanding your requirement?
J NUnicorn wranglerAuthor Commented:
basically, i wanted a way to standardize the html output and if i wanted to use a different css stylesheet i would only have to update the class.

I agree that these are both not preferred but a method to achieve the end goal.

this is a basic idea

class bootstrap_html{
	public $html = '';
	function panel( $classes = "primary" , $attr = ''){
		return '
			<div class"panel panel-'.$classes.'" '.$attr.'>

Open in new window

then the user would just instantiate the class and use it to generate the content  - obviously this is wayyyyyyyy oversimplified but i hope it gets the point across
Julian HansenCommented:
That is what I was referring to about component based generation. You have a function that outputs complex markup to create a specific component as opposed to creating an <a> element - the latter does not make sense.

With respect to the comment about the stylesheet. The idea should be that your markup remains unchanged - you swap the stylesheet that uses the existing classes to achieve a different style rather than modifying the markup to use different classes.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

I agree with Julian. This is a VERY common idea that many PHP developers get once they start becoming very comfortable with PHP and what it can do. Just about every one of us has gone through this same idea, and just about every one of us has stopped doing it, too.

1. The whole premise of CSS is separating styling from structure. By using PHP to tie classes to HTML elements, you're working against the way that CSS is intended to work.

2. This might work for some simple / basic pages upfront, but you will inevitably have more complex pages or other scenarios that require you to use HTML that might not perfectly fit into your structure. At that point, you'll be faced with either rewriting your PHP to handle those scenarios, or having to start over without the PHP side of things handling the structure, which could be difficult to undo.

3. Performance is a consideration here. I tell a lot of developers to mind the old saying, "The straw that broke the camel's back." It bears a lot of value here - PHP can do a lot of things in milliseconds. However, when you start adding lots of layers that each take milliseconds, it can grow into SECONDS of processing time after a while, and by that time, it will be VERY difficult to fix performance. Just like removing one straw from the camel's back won't do much, you'll have to address a LOT of layers to gain any significant savings on performance.

So whenever you can, avoid over-engineering. What you're proposing doing should really be tackled in just standard HTML and CSS. If you have someone that is constantly breaking the HTML itself, then that person needs more experience with HTML before they work on your pages.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
J NUnicorn wranglerAuthor Commented:

Thank guys

I am more concerned because i am relying on a third party (ie bootstrap) to perform the bulk of the css. If they make major changes like they did from 3  to 4 then rewriting classes/html or adding the old classes to the stylesheets would need to occur.

Is there an approach that could minimize this?
J NUnicorn wranglerAuthor Commented:
Obviously not relying on a third party is an option
That's basically what it comes down to - if you rely on a 3rd party, then you're at their mercy when it comes to stylesheets (and you could choose to just not use the new ones).

If you just want some better management of your styles, you could look into a preprocessor option like Sass. There are quite a few resources on the internet about it, so Google around or try out this link for a description to see if it's of any use to your situation:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.