I want to echo out the php code itself for educational purposes. Is this possible? At the same time I also need the code as php code to be executed.
adding html special-chars to this:
$this->art = file_get_contents("$this->Mainpage/$this->dir/$this->article");
it becomes:
$this->Art = htmlspecialchars( file_get_contents("$this->Mainpage/$this->dir/$this->Artikel"));
But this still does not output the code itself as the php interpreter seems to get hold of the code and directly interprets it. htmlspecialchars () has only got an effect on the html code, you then get to see the article in brackets.
I also tried using .html files instead of .php files. But PHP interprets it even if you rename it to .jpeg.
I'm at my wit's end. I would be grateful for any answer. Thanking in advance.
I dont understand, why one would actually consider doing it this way, but it is pretty easy. file_get_content will not run the code, while include will.
define('DS', DIRECTORY_SEPARATOR);
// Logic starts here
public function main() {
echo '<hr><pre>' . $this->educlude($this->Mainpage . DS. $this->dir . DS . $this->Artikle) . '</pre>';
}
public function educlude($file) {
include $file;
return htmlspecialchars(file_get_contents($file));
}
This will echo
Hello World
<?php echo 'Hello World';
for given file:
<?php echo 'Hello World';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With