<B><I>Boo boo puppy</I></B> NOT:
Boo boo puppy I tried changing the content-type to "text/plain" instead of "text/html" but that didn't help.
I tried printing out the Javascript code to print it out with a document.write but that fails when Javacript encounters a quote mark in the data which ends the string.
Surely there's a way to do this? Thanks for your help.
This came about because I was writing an HTML optimizer to reduce my filesize after I uploaded pages, and I wanted to test it by looking at the code. But I found I couldn't actually look at the code, because when I output it to the page it got rendered as a web page. At that point I could choose View Source, but that seemed so...inelegant.
I know the < works too, but I'm interested in that simple solution that I suspect must be out there! :)
That's the only way, to search & replace the <> signs?
$lt='<';
$gt='>';
#opening tag with or without a /, followed by anything
#not a >, followed by a >, global
$output =~ s/(<\/*)([^>])+(>)/$lt$2$gt/g;
$output = qq¦<PRE>$output</PRE>¦; #for line breaks
print "content-type:text/html\n\n";
print $out;
Probably can be done in a better way, but you get the idea. Exchange the double-line pipe in the qq for the qq separator of your choice.
View source in the browser?
Yeah, but I mentioned that I'd rather not do this....
Or output the page with extension .txt instead of .html
Uh, when you're writing to the screen there is no extension. It's not a file.
you could try a <textarea> tag. They don't pick up tags.
Ah, this is exactly the kind of solution I was looking for. Thanks!
It's actually pretty easy. Stow all your output in a single variable, it doesn't hog that much memory:
Thanks, that's good to know. I'll add that to my database of tricks.
Thanks again everybody for your help.
For example, if you want to include a <textarea> tag into your <textarea>. It will break the page.
I thought of that as soon as I saw the suggestion. Most of the code I'm outputting won't have a <TEXTAREA>, and when there is one I guess I'll search and replace it with something else.
Yeah, as long as I'm searching & replacing I guess I could just search & replace the <> tag markers and output the actual code instead of using <TEXTAREA>, but for some reason I'm drawn to the <TEXTAREA> solution.
This:
$markup = "<html><head><title>Tester</title></head><body><p>Test!</p></body></html>";
echo htmlSpecialChars($markup); ...should output this:
<html>
<head>
<title>Tester</title>
</head>
<body>
<p>Test!</p>
</body>
</html> ...if I'm not mistaken (minus the linebreaks which I put in to keep from breaking the page)...
-B
as long as I'm searching & replacing I guess I could just search & replace the <> tag markers and output the actual code instead of using <TEXTAREA>, but for some reason I'm drawn to the <TEXTAREA> solution....
Michael re-check my post, it does both what DrDoc says (surrounds your output in <pre> tags) and does the s & r without error (I use it all the time.)
As for entities in a text area - many entities, in the format &label; or &#number;, will convert to their visual equivalent in a text area box. Some do and some don't. For example, [ resolves as a [ in a text area box. I know this because I'm dealing with this issue at the moment. :D
The point is if you output to a text area box, you may not be actually SEEING what you hope to see unless you view source. Using the pre tags will output literally.
I'm still drawn to the <TEXTAREA> solution, since it'll work on most of the pages I'm working with, and since I can pull it out of my head (unlike the search & replace solution, which would require that I go look it up, since I'd never remember the regular expressions).
Then there's something wrong with the perl script (or the browser)...
Aha! Let me say that again: Aha!
I was starting to suspect that it might be a browser issue. I'd been testing in Safari. I just tried in Explorer and I get the HTML code just fine. I also found a workaround for Safari: If I remove the <HTML> tag from the very beginning, then Safari plays nice, too and prints just the code rather than interpreting it.
[blue]#!/usr/bin/perl
print "Content-type: text/plain\n\n";
print '<HTML><B><I>Boo boo puppy!</I></B></HTML>';[/blue]