954,193 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

View HTML source in php page?

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?

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

Assuming the generated page is stored in a variable $page:

echo '<textarea name="source">'.htmlspecialchars($page).'</textarea>';
php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

Assuming the generated page is stored in a variable $page:

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 = "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.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

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 tags. Long, and messy, but it seems to be working just fine.

Thanks.

nathanpacker
Posting Whiz in Training
234 posts since May 2005
Reputation Points: 10
Solved Threads: 0
 

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

ob_start();

//page creation goes here
//...

$page=ob_get_contents(); //get the page

echo '<textarea name="source">'.htmlspecialchars($page).'</textarea>';

ob_end_flush(); //output to browser
php_daemon
Junior Poster
140 posts since Aug 2006
Reputation Points: 13
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You