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?

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

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

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:

$page = "<html><body>content...";

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.

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.

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
This article has been dead for over six months. Start a new discussion instead.