include with html file

Asked

Viewed 369 times

0

Galera assembled a file called php.php as follows:

<?php

$nome = "nome";
$idade = "25";
$peso = "78";

include "layout.html";

This file includes the layout.html file, which is so:

<table align="center" border="1">
<tr>
    <td>
        Nome
    </td>
    <td>
        Idade
    </td>
    <td>
        Peso
    </td>
</tr>
<tr>
    <td>
        variavel
    </td>
    <td>
        variavel
    </td>
    <td>
        variavel
    </td>
</tr>
</table>

My question is. How to make php put variables into html, if you change html to php.

Does anyone know any way? I thought of creating a function that would exchange everything that counts% within html for $. Example:

%%nome%% would be traded for $nome.

Does anyone have any solution?

2 answers

3

Try it this way:

<table align="center" border="1">
<tr>
    <td>
        Nome
    </td>
    <td>
        Idade
    </td>
    <td>
        Peso
    </td>
</tr>
<tr>
    <td>
        <?php echo $nome; ?>
    </td>
    <td>
        <?php echo $idade; ?>
    </td>
    <td>
        <?php echo $peso; ?>
    </td>
</tr>
</table>
  • not sure, for this to work I would have to change the file to . php and want to keep it as . html understood

  • You would have to replace the tags in the html file, of course changing the file extension is better.

  • this I know, good what I’m trying to do and php.php take the layout.html and put the variarei inside, and the layout.htlm serves only to assemble the layout and php and who assembles the page, understood?

  • Buddy, I just tested the answer I gave you and it worked. Includes html in PHP and the variables I set in PHP appeared normal in .html. Which error appears to you?

  • here only works if I change the layout.html file to layout.php

2

I found something that might help you in https://stackoverflow.com/a/11312349/5269616

To work, you need to enable PHP to recognize HTML files as well.

To do this, create a file .htaccess in the root from your web directory and add that line:

AddType application/x-httpd-php .htm .html

So you can use PHP inside HTML files, without changing the extension.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.