文本显示标签

时间:2017-12-01 21:57:44

标签: php html tags posting

那么这段代码有什么问题? $ content包含带有html标签的文本,但是,当我发布内容时,标签不起作用并显示为纯文本。

    <?php
        require_once("nbbc/nbbc.php");
        $bbcode = new BBCode;
        $sql = "SELECT * FROM posts ORDER BY id DESC";
        $res = mysqli_query($db, $sql) or die(mysqli_connect_error());
        $posts = "";
        if (mysqli_num_rows($res) > 0){
            while($row = mysqli_fetch_assoc($res)) {
                $id = $row['id'];
                $title = $row['title'];
                $content = $row['content'];
                $date = $row['date'];

                $output = $bbcode->Parse($content);
                    if (strlen($output) > 1000) {
                        $stringCut = substr($output, 0, 1000);
                        $output = substr($stringCut, 0, strrpos($stringCut, ' '))." ... <a href='view_post.php?pid=$id'>Lasīt Vairāk</a>"; 
                    }
                $posts .="<div><h1 style='margin-left:0'><a href='view_post.php?pid=$id'>$title</a></h1><p style='margin:3px; font-style:italic; opacity: 0.6;'>$date<p><p>$output</p></div><hr>";
            }
            echo $posts;
        } else {
            echo "Oops, no new posts";
        }

    ?>

1 个答案:

答案 0 :(得分:0)

如果$content存储为已编码,即标记已转换为&lt;&gt;,则使用PHP本机函数html_entity_decode($content)将其解码为实际< }和>个字符。

html_entity_decode — Convert all HTML entities to their applicable characters