Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using PHP Text-from-File to Show Date and Version Number

    At the footer of each page, I have the copyright year and the version number of the code.

    Normally, I would have to go back to each page I have created and update the copyright year and the version number, as time goes on.

    Instead, I am interested in a simple PHP script, that will print the copyright year from one text file and the version number from another. (or one text file to do both, whichever is simplier in PHP)

    I tried Googling this, but I wasn't sure how to explain it in a set of keywords, so I couldn't find anything relevant.

    Thanks a lot in advance.

    EDIT: If you'd like to see the way the copyright year and version number look, here's the page in question.
    Last edited by AdemoS; 02-26-2007 at 04:29 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Create a file called copyright.php and have that file read the information from the file. Then use include('copyright.php') in all of your pages.

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hmm, well thank you for the quick reply.

    However, being a beginner to PHP I don't know how to "have...[copyright.php]..read the information from the file" I wouldn't even know where to start.

    I'm not asking the experts here to do the work for me, but if they know what the PHP technique I want to use is called and can give me a good set of keywords, I'd be willing to track down a tutorial myself.

    Or someone can just type out what the script should look like, if they're in the mood to do so.

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    My apologies... I usually go with a high level answer and then narrow down with details if needed.

    The easiest way to bring in the contents of a file is with the function file().

    This puts each line of the file into an array.

    Let's make this as easy as possible, and assume your file has two lines, the first line containing the copyright year, and the second line containing the version number.

    footerinfo.txt
    Code:
    2007
    2.0.5.1
    The copyright.php would look something like this:

    PHP Code:
    $footerInfo file('footerinfo.txt');

    print 
    "Copyright ".trim($footerInfo[0]).", version ".trim($footerInfo[1])n"; 
    Then just include copyright.php in your pages:

    PHP Code:
    include('copyright.php'); 

  • #6
    New Coder
    Join Date
    Sep 2006
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Aha! Thanks so much Fumigator, that's perfectly what I needed!

    aedrin: Thanks also, I'll have to look through that if I ever need the function for other uses in the future.

    EDIT: Fumigator : / I tried to give you rep but got this message:
    You must spread some Reputation around before giving it to Fumigator again.
    I'll be sure to give you some next time I'm allowed to.

  • #7
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    if I ever need the function for other uses in the future.
    It's a very useful feature of PHP, so I'm sure you will.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •