User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,809 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,524 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1918 | Replies: 4
Reply
Join Date: May 2005
Posts: 228
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

View HTML source in php page?

  #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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: View HTML source in php page?

  #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 5:17 pm.
Reply With Quote  
Join Date: May 2005
Posts: 228
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: View HTML source in php page?

  #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  
Join Date: May 2005
Posts: 228
Reputation: nathanpacker is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: View HTML source in php page?

  #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  
Join Date: Aug 2006
Posts: 138
Reputation: php_daemon is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
php_daemon php_daemon is offline Offline
Junior Poster

Re: View HTML source in php page?

  #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 11:25 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:22 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC