简体   繁体   English

带有HTML标签的文本样式

[英]Style text with HTML tags

I have a string saved in a database as <b>hello</b> 我有一个字符串另存为<b>hello</b>

When I get the string from the database using a query, the text isn't bold (which should be caused by the <b> tags). 当我使用查询从数据库中获取字符串时,文本不是粗体的(这应该由<b>标记引起)。 Instead, it simply displays as 'hello'. 相反,它只是显示为“ hello”。

How can I apply the html tags to the text ? 如何将html标签应用于文本?

<?php
$stmt = $con->prepare("SELECT * FROM posts");
$stmt->execute();
$text = $row['text'];
echo $text;
?>

I have tried using htmlentities as well as html_entity_decode , but the result is the same. 我已经尝试使用htmlentities以及html_entity_decode ,但是结果是相同的。

I'm unable to use html tags in the output ( $text = "<b>" . $row['text'] . "</b>"; ) as I'm getting multiple strings from the database, each with different html tags. 我无法在输出中使用html标记( $text = "<b>" . $row['text'] . "</b>"; ),因为我从数据库中获取了多个字符串,每个字符串不同的html标签。

@Fred-ii- Hi Fred, just to let you know that I tried htmlspecialchars_decode(stripslashes($row['text'])) again and out of the blue, it strangely worked. @ Fred-ii-嗨,弗雷德,只是想让您知道,我再次尝试了htmlspecialchars_decode(stripslashes($ row ['text'])),但结果却很奇怪。 – The Codese – The Codese

As stated in comments: 如评论中所述:

htmlspecialchars_decode(stripslashes($row['text']))

is what should have been used. 是应该使用的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM