donglingsai2880 2016-08-09 08:41
浏览 38

too long

I am storing formatted string in database using PHP. And displaying that string in td of HTML table. My sample text is like-

<font color="#0033CC"><b>water </b>releasing<i> H<sub>3</sub>O<sup>+</sup></i> ions; </font>

When displaying in td, it just displaying this raw data instead of formatted text. I have viewed the source in browser and found below data.

<td>&lt;font color=&quot;#0033CC&quot;&gt;&lt;b&gt;water &lt;/b&gt;releasing&lt;i&gt; H&lt;sub&gt;3&lt;/sub&gt;O&lt;sup&gt;+&lt;/sup&gt;&lt;/i&gt; ions; &lt;/font&gt;</td>`

That means " is replaced with &quot; > is replaced with &gt; and so on.

Is there any built in approach in PHP to avoid this scenario and displaying formatted text?

Thanks in advance!

  • 写回答

3条回答 默认 最新

  • dongpu3347 2016-08-09 08:46
    关注

    You could use html_entity_decode();

    <?php
    $orig = 'J\'ai "sorti" le <strong>chien</strong> tout à l\'heure';
    $a = htmlentities($orig);
    $b = html_entity_decode($a);
    
    echo $a; // J'ai &quot;sorti&quot; le &lt;strong&gt;chien&lt;/strong&gt; tout &amp;agrave; l'heure
    echo $b; // J'ai "sorti" le <strong>chien</strong> tout à l'heure
    
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角