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
View Html Within A Page
Moderator: General Moderators
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
or did you want an iframe? i've seen that used too.
html for page:php to display page:
pre takes an optional width. if you set it, then that's the number of characters it will display on the screen
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 */
?>html for page:
Code: Select all
<iframe name="show-source" src="show-shource.php?page=page_to_display">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>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
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