我目前正在开发类似CMS的东西,但不使用任何数据库。 对我来说一个非常大的问题是你如何改变(以后通过tinymce(或类似)格式化内容)然后将其保存到php文件中?
我的每个页面的配置文件如下所示:
<?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'; ?>现在,我希望能够在浏览器中打开一个脚本,我可以在其中选择要编辑的文件,并查看内容为$ title,$ contenttitle和$ content的文本框。 所以,实际上我们打开一个文件,查找这3个变量,显示它们的内容并更改它们(覆盖文件)。
怎么解决这个问题?
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?
最满意答案
这只是一个可以帮助您的示例方法:
写一个php / html文件,它会打印出一份表格给你:
<form method =“post”> <input type =“text”name =“title”value =“”/>
<input type =“text”name =“contenttitle”value =“”/>
<textarea name =“content”>“>
<input type =“submit”value =“save”/> </ form>
在php文件中处理表单:
if(!empty($ _ POST)){
$ result = array('title'=> htmlspecialchars($ _ POST ['title']),'contenttitle'=> htmlspecialchars($ _ POST ['contenttitle']),'content'=> htmlspecialchars($ _ POST ['content' ]));
//通过序列化$ filename = uniqid()将其保存到文件中。'。text'; //你可以玩文件名,重写这一行,以便它符合你的惯例 - 你可以使用文件的计数器
file_put_content($ filename,serialize($ result));
}
要检索文件并打印,请使用以下内容:
$ file = $ _GET ['name']; $ file = str_replace(array('/','。','\'),'',$ file); //出于安全原因
$ content = file_get_contents($ file。'。text'); //注意这是一个示例扩展
$ data = unserialize($ content);
echo'<h1>'。$ data ['title']。'</ h1>';
echo'<h2>'。$ data ['contenttitle']。'</ h2>';
echo'<p>'。$ data ['content']。'</ p>';
This is just an example approach that may help you:
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>
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));
}
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>';
更多推荐
发布评论