dongmeiba6151 2013-01-29 13:41
浏览 89
已采纳

当HTML在PHP变量中时,在HTML中使用PHP变量

I've got a .php script. In a variable I have a added html, but in that html I want to get text from another variable, how do I do this?

This is the variable with html:

$ai_boc   = '
<html>
<head>
  <title>Notes by Douno</title>
</head>

<body>
<div align="center">
<div style="width:600px; height:auto; border-radius:10px; background-color:#F7F1B8; background-repeat: auto; font-family:Georgia;  color:#513414;">

    <div style="height:100px; padding-top:20px; padding-left:20px; text-align:left;">
    <p style="margin-bottom:0px; font-weight:bold; font-size:xx-large;">$ai_su</p>
    <p style="margin-top:5px; font-size:x-small; font-weight:bold;">$ai_da</p>
    </div>
        <div style="height:1px; background-image: url(http://dl.dropbox.com/u/99775621/divider.jpg); display:block; position:relative;">
        </div>
    <div style="position:relative; overflow:hidden;">

        <div style="height:auto; width:375; padding-left:20px; text-align:left; position:relative; float:left;">
            <div style="width:375px;"> <p style="font-size:x-small; font-weight:bold;"><?php echo $ai_bo?></p>
            </div>
        </div>

        <div style="height:auto; width:160px; padding-left:20px; padding-right:20px; text-align:left; position:relative; float:left;">
        <p style="font-size:x-small; font-weight:bold; vertical-align:bottom;">If this email is considered spam, please contact us.</br></br>This email was send via Notes. An Android app developed by Douno.</p>
        <a href="https://play.google.com/store/apps/details?id=appinventor.ai_L_Bogaerts_95.Notes">
        <img alt="Get it on Google Play"
        src="https://developer.android.com/images/brand/en_generic_rgb_wo_45.png" />
        </a>

        </div>

    </div>
        <div style="height:1px; background-image: url(http://dl.dropbox.com/u/99775621/divider.jpg); display:block; position:relative;">
        </div>
    <div style="height:100px; width:600px; display:inline-block; position:relative;">

    </div>      






</div>
</div>
</body>
</html>
';

I coudn't find any working explanation, so I hope someone here can help me further. The html is not finished... Still some changes I'm gonna make.

  • 写回答

9条回答 默认 最新

  • dousao6313 2013-01-29 13:43
    关注

    Use either string concatenation, or variable expansion:

     $html = '<html>'.$somevar.'</html>';      // concatenation
     $html = "<html>$somevar</html>";           // expansion, only works with double quotes (")
    

    But much better is to use a decent template system to separate HTML and PHP altogether.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(8条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器