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.

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

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?