0

我没有找到任何与我的问题相关的帖子,所以我开始了:

我添加了trumbowyg(它是一个所见即所得的编辑器)来编辑我的内容,<textarea></textarea>当我将它发布到我的数据库中时它工作得很好。

唯一的问题是:我如何回应它?

trumbowyg的解析方法采用这种形式:你点击,比如说文本区域顶部工具栏中的B,它会将你的文本加粗。但是在服务器中,一旦发布,它实际上采用这种形式:<strong>some text</strong>

显然,当我在我的 sql 请求的这一部分中回显存储数据的 var 时,它以相同的方式输出它:<strong>some text</strong>而不是一些文本

我不知道它是否真的如此简单以至于我似乎无法找到解决方案,或者我正在尝试一些不可能的事情......?

提前谢谢你们!

4

1 回答 1

1

Well... Guess it was so obvious that I didn't find the answer in here. If it can help people who find themselves in the same situation as me : just wrap your var containing html with html_entity_decode($var)... That's it.

See below (textarea is showed if the user consulting the profile is the one wich it belongs to, else it just echo the descrption (called in an Action.php file, I didn't put the "requires" before the <!DOCTYPE html> declaration.

<!DOCTYPE html>
<html lang="en">
<?php include "includes/head.php"; ?>
<body>
    <?php include ("includes/navbar.php") ?>
    <div class="container">
    <h2><?= $user_pseudo;?></h2>
    <h5><?= $user_access_level;?></h5>
    <?php
    if($_SESSION['id'] == $user_id){
    ?>
    <form method="POST">
        <textarea id="parse" name="description"><?= $user_description; ?></textarea>
        
        <button class="btn btn-primary" name="validate" type="submit">Mettre à jour</button>
    </form>


    <?php
    } else {
    ?>
    <br/><br/><br/>
    <div class="container">

        <?= html_entity_decode($user_description) ?>
    </div>
    </div>
<?php
}
?>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="js/vendor/jquery-3.3.1.min.js"><\/script>')</script>
        <script src="trumbowyg/dist/trumbowyg.min.js"></script>
        <script>
        $('#parse').trumbowyg();
    </script>
</body>
</html>

于 2022-03-04T16:06:28.953 回答