problem with count()-ing array members
Posted: Wed Oct 07, 2009 4:46 pm
Hi,
This is my first time here, please be gentle!
I have a file that is a series of data, delimetered by :::: in reverse order. The file is updated (prepended, if thats a word!) with new data so it reads something like
October09::::October07::::September30:::: etc etc.
I got the following code from the php.net website and it works fine, as far as I can see:
But, in another php file, I have the following:
But when I do a count($arr), I get one more data entry than is present. For instance,
if the masterfile contains just "October09::::" count returns 2 !
Can anyone see what is amiss?
Thanks
Paul
This is my first time here, please be gentle!
I have a file that is a series of data, delimetered by :::: in reverse order. The file is updated (prepended, if thats a word!) with new data so it reads something like
October09::::October07::::September30:::: etc etc.
I got the following code from the php.net website and it works fine, as far as I can see:
Code: Select all
$ini_handle2 = fopen("masterfile.txt", "r");
$ini_contents2 = fread($ini_handle2, filesize("masterfile.txt"));
fclose($ini_handle2);
$handle2 = fopen("masterfile.txt", "w+");
$writestring2 = $dayfile . "::::" . $ini_contents2; // write the new data ahead of the old
if (fwrite($handle2, $writestring2) === false)
{
echo "Cannot write to text file. <br />";
}
fclose($handle2);
Code: Select all
$f = "masterfile.txt";
$file_contents = file_get_contents( $f );
$arr = explode( "::::", $file_contents ); // get the individual data, and place in an array
foreach( $arr as $i )
{ // etc. etc.
if the masterfile contains just "October09::::" count returns 2 !
Can anyone see what is amiss?
Thanks
Paul