hi james,
try this:
$calArchArray =file($YOUR_PATH."test.dat");
array_push($calArchArray,date("y").date("m"));
sort($calArchArray);
$lengthArchive=count($calArchArray);
$calArchive = fopen($YOUR_PATH."test.dat", "w");
if(!$calArchive)echo "Something screwy is going on here.";
for($n=0; $n<$lengthArchive; $n++){
if(substr($calArchArray[$n],-1)!="\n")
{
fwrite($calArchive, $calArchArray[$n]."\n");
} else {
fwrite($calArchive, $calArchArray[$n]);
}
}
echo count($calArchArray);
fclose($calArchive);
i think the problem with your code is
that you where looking for '\n' or empty
fields but this never happens because
you attach the '\n' to the end of each
field before writing it to file
hth
chris
james wrote:
Here is the code:
$calArchArray = file("$DOCUMENT_ROOT/yg/yg/calendar/calArchive.dat");
array_push($calArchArray, date("y").date("m"));
sort($calArchArray);
$lengthArchive=count($calArchArray);
for($t=0; $t<(count($calArchArray)); $t++){
if($calArchArray[$t]=="\n" || $calArchArray[$t]=="" || $calArchArray[$t]==" "){
for($y=$t; $y<((count($calArchArray))-1); $y++){
$calArchArray[$y]=$calArchArray[($y)+1];
}
array_pop($calArchArray);
}
}
$calArchive = fopen("$DOCUMENT_ROOT/yg/yg/calendar/calArchive.dat", "w");
if(!$calArchive)echo "Something screwy is going on here.";
for($n=0; $n<$lengthArchive; $n++){
$calArchArray[$n].="\n";
fwrite($calArchive, $calArchArray[$n]);
}
echo count($calArchArray);
fclose($calArchive);
This should put a newline after every date pushed into the array, but instead each run of the script adds a continually increasi....