PHP code for Copyright 2008 -> 2009 autochange code ?

Discussion in 'HTML & Website Design' started by NicknameJustin, Oct 22, 2008.

  1. #1
    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.
     
    NicknameJustin, Oct 22, 2008 IP
  2. dura_killer

    dura_killer Peon

    Messages:
    684
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think this will work

    Copywrite 2008-<?php date("Y"); ?>
    Code (markup):
     
    dura_killer, Oct 22, 2008 IP
  3. NicknameJustin

    NicknameJustin Active Member

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #3
    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.
     
    NicknameJustin, Oct 22, 2008 IP
  4. rochow

    rochow Notable Member

    Messages:
    3,991
    Likes Received:
    245
    Best Answers:
    0
    Trophy Points:
    240
    #4
    Close, but you have to echo it so it displays :)

     
    rochow, Oct 22, 2008 IP
  5. NicknameJustin

    NicknameJustin Active Member

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    Thanks for adding the echo rochow.
    Now it works!
     
    NicknameJustin, Oct 23, 2008 IP
  6. shipit

    shipit Active Member

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #6
    Copyright ©2008-<?php echo date('Y'); ?>
     
    shipit, Oct 23, 2008 IP
  7. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #7
    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...
     
    blueparukia, Oct 23, 2008 IP
  8. rochow

    rochow Notable Member

    Messages:
    3,991
    Likes Received:
    245
    Best Answers:
    0
    Trophy Points:
    240
    #8
    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 :)
     
    rochow, Oct 23, 2008 IP
  9. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #9
    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 ;)
     
    blueparukia, Oct 23, 2008 IP
  10. rochow

    rochow Notable Member

    Messages:
    3,991
    Likes Received:
    245
    Best Answers:
    0
    Trophy Points:
    240
    #10
    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.
     
    rochow, Oct 23, 2008 IP
  11. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #11
    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.
     
    blueparukia, Oct 23, 2008 IP
  12. rochow

    rochow Notable Member

    Messages:
    3,991
    Likes Received:
    245
    Best Answers:
    0
    Trophy Points:
    240
    #12
    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?
     
    rochow, Oct 23, 2008 IP
  13. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #13
    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.
     
    blueparukia, Oct 23, 2008 IP
  14. rochow

    rochow Notable Member

    Messages:
    3,991
    Likes Received:
    245
    Best Answers:
    0
    Trophy Points:
    240
    #14
    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, &copy; = Copyright, so why would you put them side by side? Copyright copyright 2008. That's the exact same as writing &trade; Trademark. - Coke is trademark trademark of CocaCola Inc.
     
    rochow, Oct 23, 2008 IP
  15. NicknameJustin

    NicknameJustin Active Member

    Messages:
    49
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #15
    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
     
    NicknameJustin, Nov 5, 2008 IP