Hello. I write something like an editor with PHP code and a problem arose in the way of creation. The code in the editor looks like this:

<html> <head> </head> <body> <?php echo 'Текст'; ?> </body> </html> 

Those. if I run this code in a PHP file just through echo , the php part will not start. If I run it through eval , it will give an error, because This is not pure php code.

So, how can you run it, that would be perceived and the part with html, and the part with php also started?

  • The easiest option is to insert a crutch in the form of a closing puff tag, namely?> Before the beginning of the file and shove it into eval - fens

2 answers 2

You do not need to download the contents of the file, but via the file_get_contents document, where your editable file will be launched via the insert. So php code will be executed and ready html code will be

  • With what file_get_contents will the puhy perform? - fens
  • He will not execute it. It will only display the content of the document on which this puff code will already be executed. Tobish let's say: file_get_contents ("index.php? File =. / Test.php") In index.php - include ($ _ GET ['file']); This is a rough code without checks, but the main point here is clear, I hope - Loner Luchador

I solved this problem in the following way:

 $dir = "./_projects/"; mkdir($dir, 0777, true); // Создаю директорию // Создаю в ней нужный мне файл $index = fopen($dir."/index.php", "w"); fwrite($index, $_GET["text"]); fclose($index); // Открываю содержимое этого файла include($dir."/index.php"); rdir($dir); // Удаляю директорию 

A pretty crutch option, but it works very well.

  • I would not throw a folder in 777. 755 - standard directory permissions, and files - 644 - Roman Kozin
  • @RomanKozin, why did not he? - Yuri
  • Because in this case, your case - anyone can delete the folder and content inside - Roman Kozin
  • @RomanKozin, okay, I'll change it, thanks :) - Yuri
  • I myself have a problem with this :) It’s better to read about permissions in Linux and understand that I’m rubbing you here :) You are welcome :) - Roman Kozin