在PHP函数之间放置html内容 [英] putting html content between php function

查看:101
本文介绍了在PHP函数之间放置html内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一些HTML内容放入一个用于使用mpdf生成PDF的变量,是否有任何方法可以将html内容分配给php函数中的变量。

i need to put some html content in a variable for generating pdf using mpdf, is there any way to assign html content to a variable in a php function.

这是我想要的。

     function getInvoice($conn,$uid,$id,$invoice_no)
        {



       echo "something";


        ob_start();
        ?>
    $content='<html>

    <body style="padding-top: 0px">
    <page>
    my html content                 
    </page><body><?php echo "something"?;></body><html>'



    <?php


    $content .= ob_get_clean();
  }

    ?>

我需要的是将html中的所有内容分配给$ content变量。
它不工作,因为它在php执行函数之间。

What i need is that the all the content in html get assign to $content variable. It is not working because it is between php execution function.

推荐答案

<?php 
function getInvoice($conn,$uid,$id,$invoice_no) {
    echo $something = "something";
    ob_start(); 
    $content='<html><body style="padding-top: 0px"><page>my html content</page><body>'.$something.'</body><html>';
    $content .= ob_get_clean();
}
?>

只要确保您的单引号和双引号正确关闭。

Just make sure you have your single and double quotes closed correctly.

注意:另外我个人更喜欢不要在HTML中给换行符,当你打算把它变成一个变量时。

Note: Also i personally prefer not to give line breaks in the html when you are going to assgin it to a variable.

这篇关于在PHP函数之间放置html内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆