开发者

Display any website source code 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 that page as HTML so i can use it i开发者_如何学JAVAn a textfield box so users can copy paste that code...

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

I have everything covered... except the display HTML thing.


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

Eval is generally frowned upon however but this is a quick and easy solution.


You need to escape the HTML into HTML entities. For instance, convert < into &lt;.


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

So, something like (if permitted) file_get_contents("http://url_of_php_file_you_were_simply_reading_not_requesting"); , then of course run that through htmlspecialchars();

Better to just use CURL to stay portable when requesting the page.


There's a php function htmlspecialchars you should look into.

For rendering check either eval (quick & dirty) or ob_start and friends (the more complex way to do it, though safer and generally supported by more hosters).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜