dqroktbn005028 2016-05-21 09:10
浏览 62

使用PHP在函数内打印HTML而不使用echo

I've no clue if what I want is possible so a "no is not possible" could also be an answer for me.

Im making a PHP function like this:

<?php
function set_block_title($post){
    echo "<p class='title'>$post->get_title()</p>";
}

I would like to do this without an echo and instead get the html out of the PHP page (mainly because the designers who will break all the PHP when they don't have the HTML syntax).

I know it's possible with an if statement like this:

<?php if( condition ): ?>
    <p class='title'>
        <?php echo $post->get_title(); ?>
    </p>
<?php endif; ?>

Is there a way to do the same thing with a PHP function? I suppose I could do something like this:

<?php
function set_block_title($post){
    <?php if( true ): ?>
        <p class='title'>
            <?php echo $post->get_title(); ?>
        </p>
    <?php endif;
}?>
  • 写回答

3条回答 默认 最新

  • dsavz66262 2016-05-21 09:14
    关注

    you can do this way also.

    <?php
    function set_block_title($post){
       $html = "<p class='title'>$post->get_title()</p>";
      return $html;
    }
    ?>
    

    try above code may helps you.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号