phphtmlechowysiwygtrumbowyg

I'm using trumbowyg as text editor for the textareas in my forum, but how do I echo it?


I didn't find any post related to my problem, so here I go :

I added trumbowyg (it's a WYSIWYG editor) to edit the content in my <textarea></textarea>, and it works just fine when I post it in my database.

Only problem is : how do I echo it ?

The parsing method of trumbowyg takes this form : you click on, let's say B in the toolbar on top of the textarea, and it will put your text in bold weight. But in the server, once posted, it takes actually this form : <strong>some text</strong>.

Obviously, when I echo the var stocking the data in this part of my sql request, it output it the same way : <strong>some text</strong> and not some text.

I don't know if it's actually so simple that I can't seem to find the solution, or if I'm trying something impossible... ?

Thanks by advance guys !


Solution

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