...

View Full Version : display html source in textarea



zapa
12-21-2003, 02:18 AM
I would like to display a html file after it has been rendered with php in Text area so user can copy or edit souce code.

I was able to open html file and print it fine. but it shows the PHP code and its not wha the final html output source looks like.

So can someone help me by showing me how i can do something like this.

thanks in advance,
zap

firepages
12-21-2003, 09:22 AM
Absolute url ...



<textarea name="whatever">
<?include 'http://domain.com/your/file.php';?>
</textarea>


would show the HTML output of file.php , wheras

include '/home/user/www/your/file.php';

would show the PHP code.

firepages
12-22-2003, 04:02 PM
DOH

Stuntboy just pointed out that the code I posted above would lead to an infinate loop and possible server death if you are trying to show HTML output of the current file !

that's not how I originally read your question but that appears to be what you actually meant ?

I am definately going to have to put a disclaimer in my sig somewhere ;)

So working on an answer now if Stunt does not beat me to it

me'
12-22-2003, 04:10 PM
Here's how it's done client side, anway: (pulled from a favelet (http://www.codingforums.com/showthread.php?s=&threadid=4437#post20550) so the code might not be completely relevant)
function(){
%20function%20htmlEscape(s){
s=s.replace(/&/g,'&');
s=s.replace(/>/g,'&gt;');
s=s.replace(/</g,'&lt;');
return%20s;
}
%20x=window.open();
%20x.document.write(
'<pre>'%20
+%20htmlEscape('<html>\n'%20
+%20document.documentElement.innerHTML%20
+%20'\n</html>'));
%20x.document.close();%20})();

ReadMe.txt
12-22-2003, 04:30 PM
how about



<?
if(!isset($_GET['sourced'])) {
echo '<textarea>';
include('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?sourced=yes');
echo '</textarea>';
}
?>


not sure about the ligitmacy of using querystrings from within an include call however.

EDIT: no more typo :p

firepages
12-22-2003, 05:06 PM
that works a treat , just a typo here

if(!isset($_GET['sourced']))

but better a typo than infinate recursion :D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum