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

Hi,

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 ( https://github.com/Airmanbzh/php-html-generator ). 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?

Thanks!
LVL 6
J NUnicorn wranglerAsked:
Who is Participating?
 
gr8gonzoConsultantCommented:
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.
1
 
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?
0
 
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.'>
		
		
			</div>
		';
	}
}

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
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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.
0
 
J NUnicorn wranglerAuthor Commented:
Hi,

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?
0
 
J NUnicorn wranglerAuthor Commented:
Obviously not relying on a third party is an option
0
 
gr8gonzoConsultantCommented:
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:

https://www.creativebloq.com/web-design/what-is-sass-111517618
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.