【问题标题】:Using a php code in a variable with multiple line strings在具有多行字符串的变量中使用 php 代码
【发布时间】:2021-03-17 23:01:51
【问题描述】:

如何在源代码部分将 $topic_image 的内容赋给这样的变量? 问题出在这里:--> src="image/<?php echo $topi_image?>" .

$display_content=<<<END_OF_TEXT
        <div>
        <img src="image/<?php echo $topic_image ?>" style="width:200px;height:150px;">
        <p style="float:left">$topic_pris</p>
        <p style="float:left">$topic_title</p>
        <p style="float:left">$topic_name</p>
        </div>
    END_OF_TEXT;

【问题讨论】:

    标签: php html css string heredoc


    【解决方案1】:

    Heredoc 扩展了变量本身。你不需要整个&lt;?php echo $topic_image ?&gt;,只需要变量:

    $display_content=<<<END_OF_TEXT
        <div>
        <img src="image/${topic_image}" style="width:200px;height:150px;">
        <p style="float:left">$topic_pris</p>
        <p style="float:left">$topic_title</p>
        <p style="float:left">$topic_name</p>
        </div>
    END_OF_TEXT;
    

    【讨论】:

    • 如何在这个变量中使用函数?我的意思是:---> $display_content=number_format($topic_pris) END_OF_TEXT;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-13
    • 1970-01-01
    • 2021-11-13
    • 2013-08-12
    • 2011-09-25
    相关资源
    最近更新 更多