dongshanfan1941 2013-12-21 18:38
浏览 20

渲染Php文件然后将其作为html返回[关闭]

I'm trying to render a php file and then return it as html to send in an email, how would I go about doing this? Here is an example of the code that I'm using:

public function setPHP($php)
{
    ob_start();
    $phpsend = ( include $php );
    $this->html = (string) ob_get_contents();
    ob_end_clean();
}

Here is how I'm calling the function.

    $php = file_get_contents( NHM_PLUGIN_DIR . 'assets/templates/newhomesguide.php' );
    $css = file_get_contents( NHM_PLUGIN_DIR . 'assets/css/email_template.css' );

    $cssToInlineStyles->setPHP($php);
    $cssToInlineStyles->setCSS($css);

I'm trying to modify CSSToInlineStyles by Tijs Verkoyen, which inlines css with html, I'm just trying do do the same but with a php file that has functionality.

enter image description here

  • 写回答

1条回答 默认 最新

  • dtz46697 2013-12-21 19:32
    关注

    I think you're pretty close. This is how I would do it. The evaluated file will be in $this->html like you want and it will immediately be sent to the output stream after being evaluated.

    public function setPHP($php)
    {
        if(!file_exists($php)) // Some error handling here maybe?
          die('File ' . $php . ' DNE');
    
        // Eval the $php file and store it in a variable
        ob_start();
        include $php;
        $this->html = ob_get_clean();
    
        // Send the evaluated file to the output stream
        echo $this->html;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大