|
Posted by Toby Inkster on 11/01/06 12:10
danielbaars wrote:
> that information in a flat file (an Excel file would be ideal but a
> plain text would do too) on a weekly basis and try to pull out the
> needed info with PHP. Except I don't know how yet. I don't expect any
> of you to do the work for me but if someone could point me to which
> functions of PHP I should do some research on, I'd be most grateful.
If you create a text file much like this:
20061101,Apple,Normandy
20061102,Orange,Seville
20061103,Pineapple,the Azores
20061104,Coconut,Fiji
You should be able to pull that information into PHP very easily using the
file() function; find out today's date using date(); then loop through
each line of the file comparing the first few characters of the file with
today's date, something like this:
$today = date('Ymd');
$lines = file('data.txt');
$info = FALSE;
while (!$info)
{
$thisline = array_pop($lines);
if ($today==substr($thisline,0,8))
$info = $thisline;
}
This will find you the relevent line and store it into a variable called
$info.
The rest is easy-peasy...
list($today,$fruit,$location) = explode(',', $info);
printf("Today's drink is %s juice from %s.", $fruit, $location);
See:
http://uk.php.net/manual/en/function.file.php
http://uk.php.net/manual/en/function.date.php
http://uk.php.net/manual/en/control-structures.while.php
http://uk.php.net/manual/en/function.array-pop.php
http://uk.php.net/manual/en/function.substr.php
http://uk.php.net/manual/en/function.explode.php
http://uk.php.net/manual/en/function.list.php
http://uk.php.net/manual/en/function.printf.php
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Navigation:
[Reply to this message]
|