TinyMCE and output with MySQL PHP



我已经将我的数据库设置为utf8,我的所有文件都使用utf8作为字符集,但我从tinymce插入的是html实体(

Jabbathehut

rn&a…)我试着打印b strong p等等都可以工作。但我只得到这样的纯文本:https://i.gyazo.com/bfc1c3a7ba7d22ae4673202939ab0046.png我尝试了几种解决方案:etc htmlspecialchars($htmlsanitize, ENT_QUOTES, 'UTF-8');
$getProgress = mysql_query("SELECT * FROM cms_comments WHERE article = $number AND userid = '".$_SESSION['user']['id']."'"); 
while($progressinfo = mysql_fetch_array($getProgress)) 
{           
    echo '<h4><b>Din besvarelse</b></h4>
'.htmlspecialchars_decode($progressinfo['comment']).'';

有什么建议吗?

执行插入的更好方法是使用PDO,对于select语句也可以并且应该这样做。

我想使用这种方法可以解决与将转换后的实体插入数据库有关的任何问题。

// define allowed tags
define('ALLOWED_TAGS', '<p>,<strong>,<ul>,<li>,<ol>,<em><br>');
$sContent = '';
// if form has been posted
if(isset($_POST['Create'])){
    // Read content from WYSIWYG
    if(isset($_POST['Article']) && $_POST['Article'] != ''){
        if(strlen(strip_tags($_POST['Article'], ALLOWED_TAGS)) > 10 ){
            $sArticle = strip_tags($_POST['Article'], ALLOWED_TAGS);
        }else $sError .= "[ArticleLength]";
    }
    if($sArticle == "") $sError .= "[Article]";

    // nothing in error string. proceed to insert
    if($sError == ''){
        // create an instance of the connection
        $conn   = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
        // prepare the sql
        $sSQL = "INSERT INTO cms_comments (Article, col2) VALUES (:Article, :col2)";
        $st   = $conn->prepare( $sSQL );
        // bind the input vars
        $st->bindValue(":Article", $sArticle, PDO::PARAM_STR);
        $st->bindValue(":col2", $col2, PDO::PARAM_STR);
        $st->execute();
    }
}

编辑时间。初始化文件。您可以将entity_encoding设置为raw,这意味着字符将以非实体形式存储,除了XML默认实体:& < > "

tinymce.init({
....
entity_encoding : "raw"

/: https://www.tinymce.com/docs/configure/content-filtering/encodingtypes

最新更新