HTML不解释标签

问题描述 投票:0回答:1

我正在使用htmlspecialchars()将数据保存到mysql中。在使用htmlspecialchars_decode()获取数据并在Angular中显示之前获取输出时。但与其解释HTML代码,不如将其显示为文本。

数据库中的数据

<p class="fr-tag"><span>test</span></p>

在htmlspecialchars_decode()之后显示代码

<p class="fr-tag"><span>test</span></p>

如下显示从数据库到div的输出

<div *ngIf="product.pdescription" class="mt-2 product-description">{{product.pdescription}}</div>

我也尝试使用html_entity_decode,但没有帮助。

下面是浏览器的屏幕截图

enter image description here

php html angular html-entities htmlspecialchars
1个回答
0
投票

为了使其正常工作,您应该使用innerHTML或externalHTML绑定:

<div *ngIf="product.pdescription" ... [innerHTML]="product.pdescription"></div>

但是要注意一些limitations

© www.soinside.com 2019 - 2024. All rights reserved.