[英]How to convert string into HTML string?
I have a string(variable) having value of database cell. 我有一个具有数据库单元格值的字符串(变量)。 Actually that value is html code.
实际上,该值是html代码。 I have to print that code into html page.
我必须将该代码打印到html页面中。 I found that how to convert HTML string into DOM string.
我发现了如何将HTML字符串转换为DOM字符串。 But I don't know that How to convert string into HTML string.
但是我不知道如何将字符串转换为HTML字符串。 If anyone know answer then please explain or suggest me link from where I can understand from beginning.
如果有人知道答案,请解释或建议我从一开始就能理解的链接。 Thank You.
谢谢。 Here is my code.
这是我的代码。
<?php
$dbstr = mysql_escape_string("<p>Just install and use this app.&nbsp;<strong>MENU -&gt; SETTINGA</strong></p>
");
?>
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
function fun(str) {
var div = document.getElementById('htmldiv');
div.innerHTML = str;
var elements = div.childNodes;
}
</script>
<div id="htmldiv">
<script type="text/javascript">
fun('<?php echo $dbstr; ?>');
</script>
</div>
</body>
尝试这个
$dbstr = html_entity_decode("<p>Just install and use this app.&nbsp;<strong>MENU -&gt; SETTINGA</strong></p>");
try this 尝试这个
$dbstr = htmlspecialchars_decode("<p>Just install and use this app. <strong>MENU -> SETTINGA</strong></p>");
echo $dbstr;
The reason why the tags get printed and not interpreted is, that with using the html special char coding ( <
and >
) you are actually telling the browser that you want the special chars to be printed, not interpreted. 标签被打印而不被解释的原因是,使用html特殊字符编码(
<
和>
),您实际上是在告诉浏览器您希望打印特殊字符,而不是被解释。 Since you are retrieving this from a database, changing the actual content might not be the best idea or not even possible. 由于您是从数据库中检索到的,因此更改实际内容可能不是最好的主意,甚至是不可能的。 Instead, you can decode the special chars with a built in php function:
相反,您可以使用内置的php函数解码特殊字符:
$dbstr = htmlspecialchars_decode(mysql_escape_string("<p>Just install and use this app.&nbsp;<strong>MENU -&gt; SETTINGA</strong></p>"));
$dbstr = html_entity_decode("<p>Just install and use this app.&nbsp;<strong>MENU -&gt; SETTINGA</strong></p>");
echo $dbstr;
use html_entity_decode()
function 使用
html_entity_decode()
函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.