944,052 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 8841
  • PHP RSS
Jan 23rd, 2007
0

View HTML source in php page?

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jan 23rd, 2007
0

Re: View HTML source in php page?

Assuming the generated page is stored in a variable $page:
php Syntax (Toggle Plain Text)
  1. echo '<textarea name="source">'.htmlspecialchars($page).'</textarea>';
Last edited by php_daemon; Jan 23rd, 2007 at 6:17 pm.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006
Jan 23rd, 2007
0

Re: View HTML source in php page?

Click to Expand / Collapse  Quote originally posted by php_daemon ...
Assuming the generated page is stored in a variable $page:
php Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jan 24th, 2007
0

Re: View HTML source in php page?

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.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Jan 24th, 2007
1

Re: View HTML source in php page?

Ah, I see. You could use output buffering to make it nicer:

php Syntax (Toggle Plain Text)
  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.
Reputation Points: 13
Solved Threads: 2
Junior Poster
php_daemon is offline Offline
138 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: URL parsing to get variables name
Next Thread in PHP Forum Timeline: Warning: mysql_fetch_array():





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC