Im going nuts with this issue and cant work out what the problem is.
I have an application that will run on a CentOS server as well as a FreeBSD server. I really dont want to write different write routines for both server types, not that i think i should. This should work across all server types except on a windows server but since im not deploying this application on a Windows server i wont worry about it.
Here is the issue that has been driving me nuts for about a week.
I have the following routine in my code.
$file = file ('/usr/local/app/file.cfg');
$new = array_unique($file);
$ff = fopen ('/usr/local/app/file.cfg', 'w');
foreach ($new as $line)
{
if (ereg ('^Test3:=', $line))
{
if ($line1 != yes)
{
$line = 'Test3:=127.0.0.1';
$line1 = yes;
}
else
{
$line = '';
}
}
fwrite ($ff, $line);
}
When this completes execution on a CentOS box my resulting file looks like this;
Test1:=
Test2:=
Test3:=127.0.0.1
Test4:=
Test5:=
Which is correct, but if i run the same code on a FreeBSD box the result is as follows;
Test1:=
Test2:=
Test3:=127.0.0.1Test4:=
Test5:=
I have spent about a week trying to work out why this is so. Im at whits end.
I have tried changing the write line to;
fwrite ($ff, $line . "\n");
also tried;
fwrite ($ff, $line . "\r\n"); and fwrite ($ff, $line . '');
But none of these solutions fix the newline issue on a FreeBSD server.
Anyone have any idea why? I'v never had to code any of my application differently across both OS's. The application code works fine on both OS's except when writing to or updating a file. I cant for the life of me work out why the results are different across two platforms on a write.
Thanks