Basically:
<?php
$conteudo = '<?php phpinfo(); ?>';
file_put_contents('novophp.php', $conteudo);
Handbook:
http://php.net/manual/en/function.file-put-contents.php
Or so:
$conteudo = '<?php phpinfo(); ?>';
$arquivo = fopen('novophp.php', 'w');
fwrite($arquivo, $conteudo);
fclose($arquivo);
Handbook:
http://php.net/manual/en/function.fopen.php
http://php.net/manual/en/function.fwrite.php
Having responded, some considerations
That’s probably not what you want. First of all, to do what was proposed, you need to have write permissions in the directories where you will generate PHP. In addition, maintenance would be extremely painful when the content was changed. Probably, as already commented, you should think about a database option.
There are legitimate cases where generating a .html
static can be interesting, and save many server resources, just by changing and/or removing these files when changing something in DB. I think a very good strategy for CMS systems, but leave it for when mastering the essential.
Shouldn’t you use the database to store the information? if you want to create the file just use the
file_put_content()
orfopen()/fwrite()
– rray
https://forum.imasters.com.br/topic/427668-criar-arquivophp-com-php/
– Darlei Fernando Zillmer
I don’t know, I’m new, the idea was to create the file and leave the file with the contents inside the bank, as if I had created manually, as if it were static
– Nicolas Guilherme Matheus
The best solution is to store it in a database. If you don’t know, this is the best time to learn. What you can do next is generate static HTML pages to serve as cache, but starts first by serving dynamic content from the database.
– Woss
@Nicolasguilhermematheus, Cara there are even possibilities for you to do this, but it is not feasible no, your site will become very vulnerable, never allow the user himself to write a php file, php is a server-level language. Create a database where you store these texts and display the contents using templates.
– arllondias
I thought about creating a database and storing the texts there, but I don’t know how to continue the process, someone has some topic that I can study on the subject?
– Nicolas Guilherme Matheus