简体   繁体   English

获取所见即所得编辑器的内容并将其发送到html

[英]get content of wysiwyg editor and send it to html

I am messing around with WYSIWYG-Editors and would like to get the current content of it with php and append it to html or lets say a <p> . 我在所见即所得(WYSIWYG-Editors)周围乱七八糟,想用php获取它的当前内容,并将其附加到html上,或者说<p> I have to say that I am a PHP-beginner, but i've figured out how to get the content of a .txt and echo it to my html. 我必须说我是一个PHP入门者,但是我已经弄清楚了如何获取.txt的内容并将其echo到html。

<?php
    $textfile = "text.txt";
    $text = file($textfile);
    echo $text 
?>

very simple. 很简单。 But there must be a possibility to "replace" the text.txt with a wysiwyg-editor. 但是必须有可能用“所见即所得”编辑器“替换” text.txt

Does anyone of you have a hint, i would really appreciate that. 有人有暗示吗,我真的很感激。

Thanks 谢谢

Edit: In Detail that means, i have a website index.html , with some text-content. 编辑:详细来说,我有一个带有一些文本内容的网站index.html I don't want to use a CMS but kind of a other html which can the user access textedit.html and type some sentences in a WYSIWYG editor like CK-Editor or TinyMCE . 我不想使用CMS而是希望使用其他html格式,用户可以访问textedit.html并在WYSIWYG编辑器(如CK-EditorTinyMCE键入一些句子。 textedit.html accesses the index.html and changes a defined <p> tag. textedit.html访问index.html并更改定义的<p>标记。

The content of the editor will come in most cases from a POST Request of a form. 在大多数情况下,编辑器的内容将来自表单的POST请求。

<form action="process.php" method="POST">
    <textarea name="text" id="editor"></textarea>
    <input type="submit" value="Submit" />
</form>

And then in process.php : 然后在process.php

<?php
$content = $_POST['text'];
echo $content;
?>

Of course you have to add some validation to this. 当然,您必须为此添加一些验证。 However this should give you a simple idea and get you started. 但是,这应该给您一个简单的想法并让您开始。

You can also start a google search like this: "form processing php". 您也可以像这样启动Google搜索:“表单处理php”。

EDIT 编辑

You need some kind of server-side action to do this. 您需要某种服务器端操作来执行此操作。 This is not possible with pure HTML! 纯HTML不可能做到这一点! You need to add a server-side backend. 您需要添加服务器端后端。

Just a little diagramm to illustrate this: 只是一些图表来说明这一点:

editor.html editor.html
| | sends changes to backend 将更改发送到后端
v v
backend (changes the contents of the frontend) 后端(更改前端的内容)
| |
v v
content.html content.html

This is a very poor design (to change the contents of the html file directly) but the principal is the same. 这是一个非常糟糕的设计(直接更改html文件的内容),但是原理是相同的。 In "good" setups you would have a database which holds the contents and the frontend would pull from there and the backend pushes. 在“好的”设置中,您将拥有一个保存内容的数据库,前端将从那里拉出,后端将推送。 But with pure HTML this is not possible! 但是使用纯HTML则不可能!

So let me give you some boilerplate: 因此,让我给您一些样板:

index.php: index.php:

<html>
    <head>
        <!-- add more stuff here -->
    </head>
    <body>
        <h1>Your Site</h1>
        <!-- add more stuff here -->
        <p>
        <?php
        echo file_get_contents('article.txt');
        ?>
        </p>
        <!-- add more stuff here -->
    </body>
</html>

editor.html: editor.html:

<html>
    <head>
        <!-- add more stuff here -->
    </head>
    <body>
        <h1>Your Site - Editor</h1>
        <!-- add more stuff here -->
        <form action="process.php" method="POST">
            <input type="password" name="pwd" placeholder="Password..." />
            <textarea name="text" id="editor"></textarea>
            <input type="submit" value="Submit" />
        </form>
        <!-- add more stuff here -->
    </body>
</html>

process.php: process.php:

<?php

if(!isset($_POST['text']) {
    die('Please fill out the form at editor.html');
}
if($_POST['pwd'] !== 'your_password') {
    die('Password incorrect');
}
file_put_contents('article.txt', $_POST['text']);
header("Location: index.php");
?>

This is a VERY basic boilerplate and should help you to get started. 这是一个非常基本的样板,应该可以帮助您入门。 Tweak it as you go. 随时调整。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM