'How to write rendered content between<pre><code> to a file
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.
Solution 1:[1]
Actually this is not possible in direct way. The reason is that client side rendered values can't be taken into db or used outside. What I mean, suppose you have a value calculated on client side ( like javascript giving value in id) . To make a file from rendered html is only way is to curl the url in backend and then write the content to a file.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Manish Srivastava |