trailing zero bytes when using fwrite()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaspo
Forum Newbie
Posts: 1
Joined: Wed May 14, 2008 9:55 am

trailing zero bytes when using fwrite()

Post by gaspo »

Hi, I'm searching on the internet third day for solution and I cant find it. Im using logging to file in my php application. Everything works, but sometimes are after line of log several trailing zero bytes - \0 or 0x00. I have tried to trim written string, put there parameter lenght for fputs, or used other functions to write (fwrite, fprintf) but nothing helps.

$in_file is correct path to file
$in_description and $in_text are strings with no special chars but \t

Code:

Code: Select all

 
public static function write_to_file($in_file,$in_description,$in_text='')
  {
    if (!($f_handle = fopen ($in_file, "a")))
      return $php_errormsg;
 
    $data2save = "\n".format_date(time())." ".format_time(time())." $in_description\t$in_text";
      
    fputs($f_handle,$data2save, strlen($data2save));
    fclose($f_handle);
    @chmod($in_file,0666);
    return TRUE;
  }
 
Please help me.
Post Reply