if(fwrite($fp, $guestbook->saveXML()))
{
echo "成功";
写入后并保存后,怎么实现换行,使得下次写入在不同的行

解决方案 »

  1.   

    我的意思是把post过来的内容,写入并保存在xml后,换行,后面写入和保存的内容就可以跟前面的不在同一行了
      

  2.   

    在哪输入echo " <br>";?
      

  3.   

    if(fwrite($fp, $guestbook->saveXML())) 

    fwrite($fp,"\n");
    echo "成功"; 
      

  4.   

    试过了4楼的,没效果,跟没加fwrite($fp,"\n");这个效果是一样的
      

  5.   

    if(fwrite($fp, $guestbook->saveXML())) 

    fwrite($fp,"\r\n");
    echo "成功"; 如果再不行 ,楼主贴上完整代码让大家看看
      

  6.   

    <?php
    $guestbook = new DomDocument(); //创建一个新的 DOM对象
    $guestbook->load('guestbook.xml'); //读取 XML数据
    $threads = $guestbook->documentElement; //获得 XML结构的根
    //创建一个新 thread节点
    $thread = $guestbook->createElement('thread'); 
    $threads->appendChild($thread);
    //在新的 thread节点上创建 title标签
    $title = $guestbook->createElement('title');
    $title->appendChild($guestbook->createTextNode($_POST['title']));
    $thread->appendChild($title);
    //在新的 thread节点上创建 author标签
    $author = $guestbook->createElement('author');
    $author->appendChild($guestbook->createTextNode($_POST['author']));
    $thread->appendChild($author);
    //在新的 thread节点上创建 content标签
    $content = $guestbook->createElement('content');
    $content->appendChild($guestbook->createTextNode($_POST['content']));
    $thread->appendChild($content);
    //将 XML数据写入文件
    $fp = fopen("guestbook.xml", "w"); 
    if(fwrite($fp, $guestbook->saveXML()))
    {
    fwrite($fp,"\r\n"); 
    echo "成功";
    echo "<script language='Javascript'> 
           parent.location.reload(); 
            </script>";
    }
    else
    echo "留言提交失败";
    fclose($fp);
    ?>
    我就是想把每次读进来的数据重新放在另外一行
      

  7.   

    fopen("guestbook.xml", "a+"); 
    看看
      

  8.   

    $guestbook = new DomDocument(); //创建一个新的 DOM对象
    $guestbook->load('guestbook.xml'); //读取 XML数据
    $threads = $guestbook->documentElement; //获得 XML结构的根
    //创建一个新 thread节点
    $thread = $guestbook->createElement('thread');
    $threads->appendChild($thread);
    //在新的 thread节点上创建 title标签
    $title = $guestbook->createElement('title');
    $title->appendChild($guestbook->createTextNode($_POST['title']));
    $thread->appendChild($title);
    //在新的 thread节点上创建 author标签
    $author = $guestbook->createElement('author');
    $author->appendChild($guestbook->createTextNode($_POST['author']));
    $thread->appendChild($author);
    //在新的 thread节点上创建 content标签
    $content = $guestbook->createElement('content');
    $content->appendChild($guestbook->createTextNode($_POST['content']));
    $thread->appendChild($content);
    //=========================================================
    $threads->appendChild($guestbook->createTextNode("\n"));//这样来添加换行
    //=========================================================
    //将 XML数据写入文件
    $fp = fopen("guestbook.xml", "w");
    if(fwrite($fp, $guestbook->saveXML()))
    {
    //fwrite($fp,"\r\n");
    echo "成功";
    echo " <script language='Javascript'>
          parent.location.reload();
            </script>";
    }
    else
    echo "留言提交失败";
    fclose($fp);