TinyMCE 尖括号

TinyMCE angle brackets

我刚开始使用 TinyMCE,但对其尖括号的行为感到很失望。它似乎将 <foo><foo>Foo</foo> 等输入解释为标签,尽管页面源显示这两种情况分别转换为 &lt;foo&gt;&lt;foo&gt;Foo&lt;/foo&gt;

我减少了我的代码,如下所示:

<?php
    // Simplified for SO, no file writing / reading
    $content = isset($_POST["forSo"]) ? $_POST["forSo"] : "";
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>For Stack Overflow</title>
    <script src="/tinymce/js/tinymce/tinymce.min.js"></script>
    <script>
        tinymce.init({ selector : "#forSo" });
    </script>
</head>
<body>
<?php
    // Behaves as expected, TinyMCE correctly automatically converts HTML Entities
    echo $content . "\n";
?>
    <form action="/forSo.php" method="post" enctype="multipart/form-data">
        <textarea id="forSo" name="forSo">
<?php
    // Page source shows that this has HTML Entities, still loses information
    echo $content . "\n";
?>
        </textarea><br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

如果我输入 <foo> 那么生成的页面源是:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>For Stack Overflow</title>
    <script src="/tinymce/js/tinymce/tinymce.min.js"></script>
    <script>
        tinymce.init({ selector : "#forSo" });
    </script>
</head>
<body>
<p>&nbsp;&lt;foo&gt;</p>
    <form action="/forSo.php" method="post" enctype="multipart/form-data">
        <textarea id="forSo" name="forSo">
<p>&nbsp;&lt;foo&gt;</p>
        </textarea><br>
        <input type="submit" value="Submit">
    </form>
</body>
</html>

然而 TinyMCE 似乎丢弃了文本区域的内容导致了这个(再次点击提交导致所有 $content 为空字符串):

将文本区域内的第二个 <?php echo $content . "\n"; ?> 替换为 <?php echo str_replace("&", "&amp;", $content) . "\n"; ?> 完成任务

这确实会阻止写入有效的 HTML 标签,但是像 <foo> 这样的字面意思的文本在 TinyMCE 编辑器中保留为 &amp;lt;foo&amp;gt; 而不是 &lt;foo&gt; TinyMCE 解释为 HTML 标签