Page 1 of 1
View Html Within A Page
Posted: Sat Jul 05, 2003 11:32 am
by daniel64
Is there a way with PHP to add a text box within a page of a website that will display the source code of that page?
Thus allowing the user to simply select and copy the source code of a particular page directly from that text box rather than having to right click and "view source"
Thanks
Posted: Sat Jul 05, 2003 1:42 pm
by Stoker
The PHP source or the same source as the client recives?
Posted: Sat Jul 05, 2003 1:43 pm
by m3rajk
the text area here is expecting the user has the screen tot he default 800 by 600 (why factory default hasn't switched to 1024 by 768 is something i don't get...yes that is my size and what most of my friends have. but enough ot the wold is either too dumb to change it, too lazy to change it or just don't give a <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> that unless you want your site to be exclusive, you have to plan on the user having that screen size) and you having this being set to be the top frame so i can use tha majority of the screen's width. but that's something you can change with ease.
i also KNOW that there's some undefined functions there... i purposely didn't make it entirely working so that you'll have to manipulate it in the hopes you'll learn it then. the file opening function isn't real. ditto for some others.
http://www.php.net you can look up the functions there, find the real ones and how they work
Code: Select all
<?php
/* php code */
?><textarea name="display source" cols="700" rows="100"><?php
$source_page=open_file(page_you_want_the_source_of_displayed);
echo $source_page;
?></textarea><?php
/* the rest of your page */
?>
or did you want an iframe? i've seen that used too.
html for page:
Code: Select all
<iframe name="show-source" src="show-shource.php?page=page_to_display">
php to display page:
Code: Select all
<?php
$page_you_want_the_source_of_displayed=$_GET['page_to_display'];
$source_page=open_file($page_you_want_the_source_of_displayed);
?><html><head><title>this is suppossed to be an iframe, if you see this something's wrong</title></head><body><h1>Source code is:</h1><pre><?php
echo $source_page;
?></pre></body></html>
pre takes an optional width. if you set it, then that's the number of characters it will display on the screen
Posted: Sat Jul 05, 2003 1:55 pm
by daniel64
Stoker wrote:The PHP source or the same source as the client recives?
I would like to display the source as the client recieves.
Posted: Sat Jul 05, 2003 1:59 pm
by m3rajk
then use javascript.
once it has "finished" loading, write to a text area.. you'll probably have to have them click a link or press a button on a form.
php is server side. you'll need a copy on the server for that to work.javascript... document.formName.textareaName.write()
i'm not sure of the particulars