dsa80833 2014-05-07 09:34
浏览 36
已采纳

如何从PHP中的变量打印HTML代码?

I am developing a PHP site, and have encountered the following problem. I have this line of code:

<div id="buynow"><?php echo $buynow; ?></div>

The variable $buynow has an html code (a paypal buy now button), and I would like to print/echo the html code that it gets processed.

With the current code, it prints the html code itself, not the desired result.

Thanks in advance

String:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXXXXXXXXXXX">
<table>
<tr><td><input type="hidden" name="on0" value="Colors">Colors</td></tr><tr><td><select name="os0">
    <option value="Black">Black </option>
    <option value="White">White </option>
</select> </td></tr>
</table>
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

Note: The value is replaced to XXXXXXXXX on purpose, in the code it is the original.

  • 写回答

2条回答 默认 最新

  • douzhan5058 2014-05-07 10:01
    关注

    maybe try this:

    <div id="buynow"><?php echo htmlspecialchars_decode($buynow); ?></div>
    

    or use

    <div id="buynow"><?php echo html_entity_decode($buynow); ?></div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用