Jump to content

[SOLVED] fwrite


Andy-H

Recommended Posts

Hello all, I am trying to teach myself the uses of fopen, fread and fwrite by writing a simple PHP/AJAX chat that writes and reads messages to and from a text file, I was just wondering what data needs to be escaped when using fwrite() and if there is a specific function to do this.

 

Thanks for all/any replys.

Link to comment
https://forums.phpfreaks.com/topic/130195-solved-fwrite/
Share on other sites

I have come across another problem, when I write the data to the file it overwrites the last part that was added, how can I make it add to the content of the file rather than overwrite it?

 

My current code is:

 

<?php
header( 'Cache-Control: no-cache, must-revalidate' );
header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
session_start();
$user = $_SESSION['user'];
$msg  = htmlentities($_GET['entry'], ENT_QUOTES);
$file = 'chat.txt';
$f = fopen($file, 'w');
$str = '<tr><td width="75" align="left"> ' . $user . '</td><td width="125" align="left"> ' . date("d-m-y g:ia") . '</td><td width="650" align="left"> ' . $msg . '</td></tr>';
fwrite($f, $str);
fclose($f);
?>

Link to comment
https://forums.phpfreaks.com/topic/130195-solved-fwrite/#findComment-675262
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.