I will list two existing errors:
1. Print ():
First of all, the print
is not correct, just remove it.
<--php-->
$nomeusuario = $_SESSION['nome'];
$html = str_replace('#NOMEUSUARIO#', $nomeusuario, $html);
<--html-->
Olá, <strong>#NOMEUSUARIO#</strong> seja bem vindo
The reason for this is simple.
When you use print
you will be literally displaying content.
Do not you understand?
Here's an example:
$qualquer_coisa = print('meu_nome');
This will display meu_nome
in the file, usually at the beginning since the html is after this function. But, the result will be displayed where it is called.
And the variable $qualquer_coisa
? This will have the value 1
, CASE would be working perfectly, #NOMEUSUARIO#
would be replaced by 1
.
2. $ html?!
There is a detail, I do not know if it was created by you when posting the question, but I will be considering an error.
What does $html
have? Nothing.
To solve, I suggest you make two files, for example:
A file to save pure HTML:
/public_html/html_index.html ~ Example, but leave before public_html!
Olá, <strong>#NOMEUSUARIO#</strong> seja bem vindo
/public_html/index.php
$nomeusuario = $_SESSION['nome'];
$arquivo = 'html_index.html';
// Caminho de exemplo!
$html = file_get_contents( $arquivo );
// Carrega o HTML, do outro arquivo.
$html = str_replace('#NOMEUSUARIO#', $nomeusuario, $html);
echo $html;
// Exibe o HTML, já alterado.
Why this?
The file_get_contents()
will get the HTML of the other file, which is pure HTML, so str_replace()
will just replace the content that was previously loaded.