2016-09-29 4 views
0

は、文字セットとしてUTF8を使用しているが、TinyMCEのからの私のインサートは、HTMLエンティティ(& LTであり、p & GT; Jabbathehut & LT;/P & GT ; rn & a ...) 私はb、strong、pなどが働いているので、印刷しようとしています。私はいくつかのソリューションを試してみましたhttps://i.gyazo.com/bfc1c3a7ba7d22ae4673202939ab0046.png ::などhtmlspecialchars($htmlsanitize, ENT_QUOTES, 'UTF-8');のTinyMCEとMySQL PHPで出力

$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']).''; 

任意の提案しかし、私はこれだけのようなプレーンテキストを取得しますか?

+0

データあなたのDB、それはエンティティやタグが含まれていますか? – atoms

+0

@atomsインサートの 画像:https://i.gyazo.com/3cf236571a5dd296746fc4d16c4d4918.png –

+0

がhtml_entity_decode()は、エンティティとして挿入されているように見える –

答えて

0

挿入を実行するより良い方法は、PDOを使用することです。これは、選択ステートメントでも同じことを行う必要があります。

私はこのメソッドを使用すると、変換されたエンティティをDBに挿入することに関連する問題を解決できると思います。

// 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(); 

    } 

}