Hello Code Experts. What is the php code to include for current year in the footer, that update it automatic every new year? I guess something like: ...&year... And where should I put it? It's a single index.php website, but not a blog. Thanks, Justin.
Thanks for your reply dura_killer. This might work with some code to add in the header. It doesn't work right now. Thanks, Justin.
Though to save opening and closing PHP tags so soon, I don't see why people can't do: <?php echo 'Copyright ©2008-'. date('Y'); ?> PHP: It looks so much neater to me...
Though to save opening and closing HTML tags so soon, I don't see why people can't do: The same way you separate HTML and CSS, HTML & PHP should be separated
Exactly, but not to the point of insanity. PHP tags sgould only really be opened and closed once because unlike HTML/CSS, it can affect the server
It doesn't matter how many times it's opened/closed - the PHP inside will generate far more server load that reading "<?php ?>". Likewise adding 500 divs, it'll slow it down a touch but nothing noticeable. PHP is a "logic" layer, HTML is a "layout/markup" layer. They should be separated the same way "structure" is separate from "presentation". It is lazy programming to just mush them together any-old-how. You obviously haven't had to cleanup after a $5 indian programmer; you'd understand more if you had to edit a site where the entire f***'n site is echoed out everywhere amongst all the PHP.
I spend a lot of my time cleaning up PHP, anything without regex and I'm fine, I'm better in PHP than I am in HTML and CSS because I have a background in C++. $var = 'Some Tag'; $var2 = 'Meh'; $var3 = 'I feel like breaking HTML rules'; echo ' <b>'.$var.' <i>'.$var2.'</i> </b> <xmp>'.$var3.'</xmp>'; PHP: Is faster than opening and closing 3 PHP tags because it only has to open one PHP tag and perform just one echo function as opposed to three. As you said, the PHP inside the tags uses more load, so you don't want to use three functions in tthree different tags if you can avoid it.
You honestly can't argue that having HTML inside PHP is a good practice. You might as well do all your CSS inline - hey, it's faster than having to add an ID or class then tab to a stylesheet to write the rule. It's all 'cute' in your 8 line example - how about we make that 10,000 lines spread over 100 different PHP files, then we see who can change a site faster - me who has the HTML completely separate in a nice templating system, or you where every single bit of HTML is contained within the PHP and you have to trudge through every PHP file. So following this logic, the best way of coding a site is slicing and generating it in Imageready then editing it with DW, given that it'd take not even half an hour compared to a few hours doing it all by hand?
When I said faster, I meant server load wise. Using 3 echos is less load on the server than one. If I had to tab to HTML and CSS as well as doing browser testing, I'd eat myself. Tiled Windows my good man. I'll write the HTML first, then write a CSS file. And when I edit them together, they go side by side. I'll argue for what's best at the time, and using the number of variables in comparision to the size of the string. If I am the only one who'll ever touch it, I'll do it the optimal way. If someone else is going to be using it, I would do it only for the parts they don't have to touch, and use what is easier for them. I won't even use PHP in a template system because I expect people using it would do so for the HTML, and I like to keep my stuff separate, despite what it may come across. A template for my CMS: ... <meta content="" name="description" /> <title><setting:sitename></title> </head> <body> <div id="header"> <h1><setting:sitename /></h1> ... Code (markup): Is basically pure XML, the template is parsed and cached everytime the file is modified or when the theme is first selected. Meaning that every template does end up as pure (and perfectly readable) PHP for speed reasons. Using HTML inside single quotes is no different than in static HTML, you can still indent it, apply all the rules and see it as normal HTML. It'd be stupid to do it for the occasional string - like the date example I gave, which I do because I like to keep my things grouped and looking neat - but for using lots o variables in a large string of HTML, it is faster and is much more readable and easy to work with. You separate your HTML and CSS so you can reuse code and make the markup cleaner. You can make it cleaner again without adding extra tags, the word echo and a variable. Now if you read the word optimal in this reply, it'd be needless to say that if I did that, I'd be a poor excuse for a web developer, who likes to keep the finished product fast.
You still have to move the cursor. Quicker just to write it inline. The PHP tags indicate exactly that - PHP. That's almost abusing PHP, it doesn't need to be in there at all. It's not even echo'ing variables or anything - just plain text that doesn't belong in the logical layer. Off topic, © = Copyright, so why would you put them side by side? Copyright copyright 2008. That's the exact same as writing ™ Trademark. - Coke is trademark trademark of CocaCola Inc.
Thanks a lot Master Brains! You know this. By the way; Is this available to my .html site too? Probably a messy java script that has to be inserted in the <head> + in the <body> + a separate file.js, or is there an easier solution, like the sister to: <?php echo date('Y'); ?> The long version will do good if nothing easier is available Thanks in advance programmers, Justin