drvvvuyia15070493 2014-02-15 12:45
浏览 24
已采纳

whysiyg保存在php文件中

I am currently developing somthing like a CMS, but without using any database. A really big problem for me is how can you change (and later format content via tinymce (or similar) ) and then save it into a php file?

My configuration file for each page looks like this:

<?php 
$title = 'Title of the page';

$contenttitle = <<<HTML
Something like a short summary, displayed at the top
HTML;


$content = <<<HTML
main content
HTML;

$foldername = basename(__FILE__, '.php');
include '../template/standard/layout/index.php'; ?>

Now, I want to be able to open a script in the browser where I can select the file I want to edit and see text boxes with content of $title, $contenttitle and $content. So, in fact we open a file, look for these 3 variables, display their content and change them (overwrite the file).

How can this be solved?

  • 写回答

1条回答 默认 最新

  • duanjizhan9353 2014-02-15 13:03
    关注

    This is just an example approach that may help you:

    1. Write a php/html file which will print out a form for you:

      <form method="post"> <input type="text" name="title" value=""/>

      <input type="text" name="contenttitle" value=""/>

      <textarea name="content">">

      <input type="submit" value="save"/> </form>

    2. Handle your form in the php file:

      if (!empty($_POST)) {

      $result = array( 'title' => htmlspecialchars($_POST['title']), 'contenttitle' => htmlspecialchars($_POST['contenttitle']), 'content' => htmlspecialchars($_POST['content']) );

      // save it to a file by serialiing $filename = uniqid().'.text'; // you may play around with file names, rewrite this line so it will suit your convention - you may use counter of the files

      file_put_content($filename, serialize($result));

      }

    3. To retrieve file and print it use something like this:

      $file = $_GET['name']; $file = str_replace(array('/', '.', '\'), '', $file); // for security reasons

      $content = file_get_contents($file.'.text'); // note this is an example extension

      $data = unserialize($content);

      echo '<h1>'.$data['title'].'</h1>';

      echo '<h2>'.$data['contenttitle'].'</h2>';

      echo '<p>'.$data['content'].'</p>';

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向