Show any source code of the site for copy / paste

I have a website displaying data from MySQL in a php file (/something.php) .... I want to copy the source code of this page as HTML so that I can use it in a textbox so that users can copy paste this code ...

It's almost like an HTML generator using information from mySQL, so users can custimize every HTML code.

I have everything closed ... except the rendered HTML thing.

+2


a source to share


4 answers


echo htmlspecialchars(eval(file_get_contents('path/to/your/file')));

      



Eval is usually frowned upon, but this is a quick and easy solution.

+1


a source


You need to avoid HTML in HTML entities. For example, convert <

to &lt;

.



0


a source


There is a php function htmlspecialchars

in there that you should look into.

For rendering, check out either eval

(quick and dirty) or ob_start

and friends (harder way to do this, albeit safer and usually supported by other hosts).

0


a source


You need to actually request the page from the web server, not just read its contents, for PHP to execute and produce the result. That is, if I understand correctly that PHP (the file you were just reading) is asking the database to actually fetch the HTML you want to display.

So something like (if allowed) file_get_contents("http://url_of_php_file_you_were_simply_reading_not_requesting");

then of course run this viahtmlspecialchars();

Better to just use CURL to stay portable when the page is requested.

0


a source







All Articles