...

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



AdemoS
02-26-2007, 04:26 PM
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 (http://www.blkflm.com/TESTING6).

Fumigator
02-26-2007, 04:41 PM
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.

AdemoS
02-26-2007, 04:47 PM
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. :thumbsup:

aedrin
02-26-2007, 04:58 PM
http://us3.php.net/manual/en/function.include.php

Fumigator
02-26-2007, 04:59 PM
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() (http://us2.php.net/manual/en/function.file.php).

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


2007
2.0.5.1


The copyright.php would look something like this:



$footerInfo = file('footerinfo.txt');

print "Copyright ".trim($footerInfo[0]).", version ".trim($footerInfo[1])\n";


Then just include copyright.php in your pages:



include('copyright.php');

AdemoS
02-26-2007, 08:14 PM
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.

aedrin
02-26-2007, 10:03 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum