Since you didn’t mention where the variables come from, I’ll give you a general example of a system of templates:
Information from the DB:
<html>
Nome: $nome$
</html>
PHP
<?php
$contrato = /* aqui você pega do DB os dados */;
$nome = 'José Maria'.
$idade = '17';
$contrato = str_replace( '$nome$', $nome, $contrato );
$contrato = str_replace( '$idade$', $idade , $contrato );
... faça o mesmo para todos os campos ...
echo $contrato;
?>
Note that in DB it pays to use a marking that does not confuse, as $nome$
instead of $nome
, to avoid ambiguity if there is something like $nomenclatura
(that begins with $nome
also).
If you already have a lot in DB, at least be careful, with words started in the same way, change the longer ones first in the sequence of places (change the $nomenclatura
before $nome
, other than the $nome
will touch something that should not).
See the syntax of str_replace
using array to make several replacements at once:
$contrato = str_replace(
array( '$nome$', '$idade$', '$endereco$' ), // Palavras a trocar
array( $nome , $idade , $endereco ), // O que vai por no lugar de cada uma
$contrato
)
The following question may also help:
How to create a function to scroll through a dynamically created PHP page and change certain text
That’s right. Thank you very much!
– lelopes