One of the quick ways to take advantage of an existing PHP is this:
<?php
ob_start(); // Isto bloqueia a saida do PHP para a "tela"
... tudo que você faria normalmente no PHP
$gerado = ob_get_contents(); // Aqui capturamos o que seria enviado
ob_end_clean(); // E limpamos, pois já está na string
// neste momento, tudo que seria enviado para o cliente está em $gerado
// e pode ser salvo em disco
file_put_contents('arquivo.html', $gerado);
If you’re going to build a little more fancy application, you can avoid the output buffer
and generate HTML directly in string. Instead of using echo
, for example, you can concatenate in this way:
<?php
$titulo = 'Meu HTML gerado'; // normalmente vai pegar de DB ou formulario
$conteudo = 'Lorem Ipsum Batatas Doces';
// Montamos nosso HTML no PHP, da forma que quisermos
// \t é o tab, \n a quebra de linha
$html = "<html>\n";
$html .= "\t<head>\n";
$html .= "\t\t<title>".htmlentities( $titulo )."</title>\n";
$html .= "\t</head>\n";
$html .= "\t<body>\n";
$html .= "\t\t<div>".htmlentities( $conteudo )."</div>\n";
$html .= "\t</body>\n";
$html .= "</html>\n";
//... e vai montando o arquivo com variáveis etc
// e depois salva
file_put_contents('arquivo.html', $html);
Actually when the php code is executed an html is generated.For you to use pure html with php you have to create a file. php and ai you can use php and html code.
– thiago xavier
Why? I want to know the possibilities. It’s not a question based on opinions, because I don’t think there are many ways to do this. But you can always have more than one, even if there are few
– DiChrist
Yes it is possible! can use
file_puts_contents()
orfwrite()
(and the others) can do this from a template or even a textarea.– rray
comrade, before I had seen this file_puts_contents() and I got interested in it. Only it resembles fwrite (the only one I knew)?
– DiChrist
Good suggestion, I will specify better
– DiChrist
It was good! Thank you very much :)
– DiChrist