douba2705 2013-06-16 12:18
浏览 80
已采纳

获取wysiwyg编辑器的内容并将其发送到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>. 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
    $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.

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. 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. textedit.html accesses the index.html and changes a defined <p> tag.

  • 写回答

1条回答 默认 最新

  • doukuizuo1795 2013-06-16 12:27
    关注

    The content of the editor will come in most cases from a POST Request of a form.

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

    And then in 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".

    EDIT

    You need some kind of server-side action to do this. This is not possible with pure HTML! You need to add a server-side backend.

    Just a little diagramm to illustrate this:

    editor.html
    | sends changes to backend
    v
    backend (changes the contents of the frontend)
    |
    v
    content.html

    This is a very poor design (to change the contents of the html file directly) but the principal is the same. 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!

    So let me give you some boilerplate:

    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:

    <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:

    <?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.

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

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料