I have a file main.php with code snippet as
<pre><code>
echo htmlspecialchars ('echo "this is a $name of your best friend";');
</pre></code>
When I run main.php file in browser I get
echo "this is a $name of your best friend";
This output is okay.
I want to write this output to a text file - output.txt
The problem is if I try to write the content to a output.txt , I get code snippet between tags rather than output. It seems I have to run file in browser. But even after running file in browser, the content can be seen but can't be written to output.txt
How I can do it. It would be best if I can write to output.txt without opening main.php file in browser.
$fp = fopen('output.txt', 'w'); fwrite($fp, $snippet); fclose($fp);
The problem is snippet has those pre code tags. I could not figure out what code could write rendered output to output.txt
Please note: This question is not about how to write to a file.
It's about writing rendered output to a file.