View Html Within A Page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daniel64
Forum Newbie
Posts: 2
Joined: Sat Jul 05, 2003 11:32 am

View Html Within A Page

Post 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
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

The PHP source or the same source as the client recives?
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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&#39;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

&lt;iframe name="show-source" src="show-shource.php?page=page_to_display"&gt;
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
daniel64
Forum Newbie
Posts: 2
Joined: Sat Jul 05, 2003 11:32 am

Post 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.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
Post Reply