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条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程