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.

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

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?