Jump to content


Photo

page updated script?


  • Please log in to reply
1 reply to this topic

#1 patrick87

patrick87
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 26 April 2006 - 03:18 PM

The compay i am doing a website for wants a Last Updated: DATE added to the csv file of the prices page i have for them.

the script was from a person here... for the csv file..


<?PHP
############################################
# this gets the price.csv file and displays the data
#
#    IMPORTANT: Array elements begin with the number 0 (zero)
#
#    this entire example is predicated upon the use of a 
#    predetermined excel template
#
#    as you become more proficient, you will be able to
#    modify this script to dynamically adjust
#############################################

###############################################################
# read the csv file into an array
#
#    this array has elements that represent each row of the excel file
#    each element will have data separated by commas
#    we will turn each element into a new array so that we can extract the data
###############################################################

$array_01 = file("price.csv");

###################################################
# count the number of elements in the first array
###################################################

$elements_01 = count($array_01);

#######################################################################
# get the location - based upon our excel template
# this information would be the 2nd piece of data in the first element
#    in our example the first element looks like this 
#    location,London,,,,,

$array_02 = explode(",", $array_01[0]);
$location = $array_02[1];

############################################################################
# get the months for which we have prices - based upon our excel template
# this information would be the 2nd through 6th pieces of data in the 2nd element
#    in our example the second element looks like this
#    month,April,May,June,July,August

$array_03 = explode(",", $array_01[1]);
$month01 = $array_03[1];
$month02 = $array_03[2];
$month03 = $array_03[3];
$month04 = $array_03[4];
$month05 = $array_03[5];

################################################################################
####
# get the crop names as well as the relevant prices - based upon our excel template
# this information would be in the elements 3 through 5
#    in our example those elements look like this
#    corn,12.5,9.75,8,13.37,6
#    soybean,3.25,4.68,5.23,4.5,2
#    wheat,7.5,4.75,2,10.37,23.98

$array_04 = explode(",", $array_01[2]);
$array_05 = explode(",", $array_01[3]);
$array_06 = explode(",", $array_01[4]);
$crop_01_name = $array_04[0];
$crop_01_price01 = "$".number_format($array_04[1], 2, '.', ',');
$crop_01_price02 = "$".number_format($array_04[2], 2, '.', ',');
$crop_01_price03 = "$".number_format($array_04[3], 2, '.', ',');
$crop_01_price04 = "$".number_format($array_04[4], 2, '.', ',');
$crop_01_price05 = "$".number_format($array_04[5], 2, '.', ',');

$crop_02_name = $array_05[0];
$crop_02_price01 = "$".number_format($array_05[1], 2, '.', ',');
$crop_02_price02 = "$".number_format($array_05[2], 2, '.', ',');
$crop_02_price03 = "$".number_format($array_05[3], 2, '.', ',');
$crop_02_price04 = "$".number_format($array_05[4], 2, '.', ',');
$crop_02_price05 = "$".number_format($array_05[5], 2, '.', ',');

$crop_03_name = $array_06[0];
$crop_03_price01 = "$".number_format($array_06[1], 2, '.', ',');
$crop_03_price02 = "$".number_format($array_06[2], 2, '.', ',');
$crop_03_price03 = "$".number_format($array_06[3], 2, '.', ',');
$crop_03_price04 = "$".number_format($array_06[4], 2, '.', ',');
$crop_03_price05 = "$".number_format($array_06[5], 2, '.', ',');

###################################################################
# display the data in a nicely formatted table

?>

is there a easy way to add a line so that i can make a line in the csv file to add.. Last Updated: and give a date?

#2 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 26 April 2006 - 04:05 PM

$filename = 'somefile.txt';
if (file_exists($filename)) {
echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
Everything you want to know is here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users