如何在HTML文件中显示PHP文件中的变量

im having this function to call templates with .html extension from templates folder because i want to separate html from php

ok this is my function for calling template

class Template {

public $temp;

// function for reading the template from a directory
function gettemplate($template) {

    // check if path is folder
    if (is_dir('templates/')) {

        // check if file exists and if is readable
        if (is_readable('templates/' . $template . '.html')) {

            $this->temp = 'templates/' . $template . '.html';

            return $this->temp;

        } else {
            return false;
        }

    } else {
        return false;
    }

}

This class calling template from templates folder

now what i need is to make example profile.html and profile.php

in profile.html just make variables like First name : <?php echo $first_name; ?>

and in profile.php to define varibales here is profile.php

if (isset($_GET['id']) && !empty($_GET['id']) && is_numeric($_GET['id'])) {

$id     = $filters->validate_url($_GET['id']);
$data   = $users->userdata($id);
$id     = $data['user_id'];

$first_name = $data['first_name'];
$last_name  = $data['last_name'];
$username   = $data['username'];
$email      = $data['email'];
$country    = $data['country'];
$date       = $data['date'];

include ( $template->gettemplate('profile') );

and here is profile.html

<ul>
<li>First name : <?php echo $first_name; ?></li>
<li>Last name : <?php echo $last_name; ?></li>
<li>Username : <?php echo $username; ?></li>
<li>Email : <?php echo $email; ?></li>
<li>Country : <?php echo $country; ?></li>
<li>Member since : <?php echo $date; ?></li>

now my question is how do i make class to call template file just with

$template->gettemplate('profile');

and not with include ($template->gettemplate('profile'));

and to display variables from php file in html file

From php.net

Question 1 - display variables from php file in html file

Use the extract() function " to display variables from php file in html file". It will create a local variable with the name of the array key and the value of the array value

$data   = $users->userdata($id);
extract($data, EXTR_SKIP);
include $template->gettemplate('profile');

Question 2 - call template file just with $template->gettemplate('profile');

I don't believe there is a way to get around using an include. You could put the include in gettemplate and pass the data array. There are several really good template engine on the net. I recommend looking at a few. I recommend looking at Mustache