Get HTML rendering from a local PHP file

I have a PHP file for a make table with a row of data from a database. I want to send this page by email. but when I get the content, it contains HTML and PHP code. but I want to send only the result of the page in HTML.

I am using this code

    $str =  file_get_contents( 'template.php' );
    $mail = "test@tst.com";
    mail($mail,$str);

and this one

$str = readfile("'template.php'");

but the result contains php code in email. how can i get only html result?

+2
source share
2 answers
function getRenderedHTML($path)
{
    ob_start();
    include($path);
    $var=ob_get_contents(); 
    ob_end_clean();
    return $var;
}

This function will do what you want.

+7
source

file_get_contents just returns the contents of the file, while you need to execute the script and execute its output.

See this: fooobar.com/questions/122777 / ...

0
source

Source: https://habr.com/ru/post/1622751/


All Articles