Return html response from PHP page in to variable

前端 未结 2 1136
遥遥无期
遥遥无期 2021-01-23 16:12

I am trying to generate an email with some HTML that is created via another PHP file.

Email generating file is run by a cron running every hour. Another file exists that

相关标签:
2条回答
  • 2021-01-23 16:39

    Check out the built-in functions ob_start and ob_get_clean.

    You can then do something like:

    ob_start();
    include( "file.php");
    $var = ob_get_clean();
    
    0 讨论(0)
  • 2021-01-23 16:42

    If I understood what you said, you can use output buffering, so that you can get the output of htmlGenerator.php

    For example:

    ob_start();
    // as an example
    echo "Hello World";
    // or in our case
    include "htmlGenerator.php";
    $result = ob_get_contents();
    ob_end_clean();
    

    You can also create a simple function like this:

    function include_output($filename)
    {
        ob_start();
        include $filename;
        $contents = ob_get_contents();
        ob_end_clean();
        return $contents;
    }
    
    $mycontent = include_output("htmlGenerator.php");
    

    Read the php documentation for further details.

    0 讨论(0)
提交回复
热议问题