如何从数据库中呈现HTML标记

时间:2018-03-12 20:46:50

标签: javascript php html tags

我有一个mysql数据库,用于存储来自ckeditor的文本,该文本带有html标记。当我尝试使用javascript显示文本时,它会在页面上显示标签,但没有正确格式化,例如

<p><b>This text is bold</b></p>
<p><i>This text is italic</i></p>
<p>This is<sub> subscript</sub> and <sup>superscript</sup></p>

这是我的JS代码:

$("#topHeading1").text(item.articleHeading);
                $("#topArticle1").text(item.articleHeading);

                $("#topStory1Heading").text(item.articleHeading);
                $("#topStory1Date").text(item.articleDate);
                $("#topStory1Author").text(item.articleAuthors);
                $("#topStory1Content").text(item.articleBody);

                $("#topHeading1Image").attr('src', 'assets/img/' + item.articleImage);
                $("#topArticle1Image").attr('src', 'assets/img/' + item.articleImage);
                $("#topStory1Image").attr('src', 'assets/img/' + item.articleImage);

PHP代码

while ($row = $results->fetch_assoc()) {
    $articleItem = array(
        "articleId" => $row["articleId"],
        "articleHeading" => $row["articleHeading"],
        "articleBody" => nl2br($row["articleBody"]),
        "articleAuthors" => $row["articleAuthors"],
        "articleDate" => $row["articleDate"],
        "articleImage" => $row["articleImage"],
        "articleLocation" => $row["articleLocation"]
    );

    $list[] = $articleItem;
}

HTML代码

<div class="category_article_content" id="topStory1Content"> 
                                                   Content
                                                </div>

如何在我的网站上正确呈现它。

0 个答案:

没有答案