reverse htmlspecialchars

前端 未结 4 1720
梦毁少年i
梦毁少年i 2020-12-05 17:40

this may seem like a simple problem but I couldn\'t find it in the archives.

how does one reverse the effects of htmlspecialchars?

I tried something like thi

相关标签:
4条回答
  • 2020-12-05 17:46

    You need htmlspecialchars_decode(). See PHP docu on this.

    $html = htmlspecialchars_decode( $html, ENT_NOQUOTES );
    
    0 讨论(0)
  • 2020-12-05 17:49

    example :

    echo htmlspecialchars_decode(htmlspecialchars('your "strange" text with characters like !"/$%?&*'))
    

    it will echo : your "strange" text with characters like !"/$%?&*

    this is an example of encode/decode. it works.

    0 讨论(0)
  • 2020-12-05 17:49

    From what I understood, you need htmlspecialchars_decode - Docu

    0 讨论(0)
  • 2020-12-05 17:54

    Use htmlspecialchars_decode()

    <?php
    $str = "<p>this -&gt; &quot;</p>\n";
    
    echo htmlspecialchars_decode($str);
    
    // note that here the quotes aren't converted
    echo htmlspecialchars_decode($str, ENT_NOQUOTES);
    ?>
    

    Reference - PHP Official Doc

    0 讨论(0)
提交回复
热议问题