Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将ajax留言簿保存到文件_Php_Jquery_Ajax - Fatal编程技术网

Php 将ajax留言簿保存到文件

Php 将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

我已经试过使用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.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 );
} 

我还是做不到