View HTML source in php page?

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

View HTML source in php page?

 
0
  #1
Jan 23rd, 2007
Hey, I created a little form for my sister to use to create her eBay pages on the fly. Basically she inputs the background colors, text colors, description, pictures, all that jazz, and the form generates the html with the information she provided.

I want to make it easy for her to get the source code of the page, exactly as it's output, and I don't want her to have to rely on the "View Source" in IE.

So how can get all the html I've generated in my php script, and put it like in a little textarea box where she can highlight it all and copy it to her clipboard?
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: View HTML source in php page?

 
0
  #2
Jan 23rd, 2007
Assuming the generated page is stored in a variable $page:
  1. echo '<textarea name="source">'.htmlspecialchars($page).'</textarea>';
Last edited by php_daemon; Jan 23rd, 2007 at 6:17 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: View HTML source in php page?

 
0
  #3
Jan 23rd, 2007
Originally Posted by php_daemon View Post
Assuming the generated page is stored in a variable $page:
  1. echo '<textarea name="source">'.htmlspecialchars($page).'</textarea>';
Well, that's the problem, I don't really know how to store the generated page in a variable, because on the php page, it has a bunch of variables and stuff, and I don't know how to get it all stored into a variable. I tried simply doing like:
[PHP]$page = "<html><body>content...";[/PHP]

But that didn't seem to work. But maybe it's because I wasn't using that htmlspecialchars thing?

But I'll try that with what you gave me and see if it works.
Thanks.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: View HTML source in php page?

 
0
  #4
Jan 24th, 2007
Well, what I eventually did, that is working just fine, is instead of putting the page in a variable, I just copied the whole thing inbetween the <textarea></textarea> tags. Long, and messy, but it seems to be working just fine.

Thanks.
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: View HTML source in php page?

 
0
  #5
Jan 24th, 2007
Ah, I see. You could use output buffering to make it nicer:

  1. ob_start();
  2.  
  3. //page creation goes here
  4. //...
  5.  
  6. $page=ob_get_contents(); //get the page
  7.  
  8. echo '<textarea name="source">'.htmlspecialchars($page).'</textarea>';
  9.  
  10. ob_end_flush(); //output to browser
Last edited by php_daemon; Jan 24th, 2007 at 12:25 pm.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum


Views: 4940 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC