I have tried with fuction fopen, fwrite but I still can't make the it possible I want to save my ajax guest book into txt file, please help me. This is the index.php
<?php
error_reporting(E_ALL^E_NOTICE);
include "comment.class.php";
$comments = array();
foreach($comments as $c){
echo $c->markup();
}
?>
and it is the comment.class.php
<?php
class Comment
{
private $data = array();
public function __construct($row)
{
/*
/ konstruktor
*/
$this->data = $row;
}
public function markup()
{
/*
/ method untuk comment
*/
//alias untuk &$this->data
$d = &$this->data;
$link_open = '';
$link_close = '';
if($d['url']){
$link_open = '<a href="'.$d['url'].'">';
$link_close = '</a>';
}
$d['dt'] = strtotime($d['dt']);
$url = 'http://'.dirname($_SERVER['SERVER_NAME'].$_SERVER["REQUEST_URI"]).'/img/default_avatar.gif';
return '
<div class="comment">
<div class="avatar">
'.$link_open.'
'.$link_close.'
</div>
<div class="name">'.$link_open.$d['name'].$link_close.'</div>
<div class="date" title="Added at '.date('H:i \o
d M Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div>
<p>'.$d['body'].'</p>
</div>
';
}
I want to save the comment body into chat.txt
The following snippet will append the comments into the file instead of echoing them. See file_put_contents
manual for details.
foreach($comments as $c){
file_put_contents( 'chat.txt', $c->markup(), FILE_APPEND );
}