Php 将ajax留言簿保存到文件
我已经试过使用Function fopen,fwrite,但仍然无法实现 我想把我的ajax留言簿保存到txt文件中,请帮助我。 这是index.phpPhp 将ajax留言簿保存到文件,php,jquery,ajax,Php,Jquery,Ajax,我已经试过使用Function fopen,fwrite,但仍然无法实现 我想把我的ajax留言簿保存到txt文件中,请帮助我。 这是index.php <?php error_reporting(E_ALL^E_NOTICE); include "comment.class.php"; $comments = array(); foreach($comments as $c){ echo $c->markup(); } ?> 它是comment.cla
<?php
error_reporting(E_ALL^E_NOTICE);
include "comment.class.php";
$comments = array();
foreach($comments as $c){
echo $c->markup();
}
?>
它是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\n d M Y',$d['dt']).'">'.date('d M Y',$d['dt']).'</div>
<p>'.$d['body'].'</p>
</div>
';
}
以下代码片段将把注释附加到文件中,而不是重复它们。有关详细信息,请参阅
foreach($comments as $c){
file_put_contents( 'chat.txt', $c->markup(), FILE_APPEND );
}
我还是做不到