Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display HTML code?

Status
Not open for further replies.

Stickbread

Programmer
Mar 12, 2005
3
US
I'm using php to generate a javascript script... (very ugly).

In fact, this quest

I've downloaded the html source of a webpage with php, and now I would like to display that page using javascript.

I've wrapped each line in a document.write(), but I'm having difficulty with quotation marks, apostraphies, etc...

Is there any quick way to add all of the appropriate escape characters so that a block of html will be display correctly? PHP's addslashes seems to be missing a few things for javascript code.
 
If you already have the code in a PHP variable, can you just write it out with PHP? Why do you have to use JavaScript?

Adam

recursion (n.) See recursion.
 
Yup, I agree with adam0101. Use something like this:

<?php
print '<sometag>What you want to display</sometag>';?>

Can't rember the exact code on the fly, but I am fairly sure this is it, or at least very close. Hope it helps.
 
to print a quote mark with javascript preceed it with a backward slash ie. \"

this is also required for other "special" characters in Javascript to get them to print into the HTML.

Kevin Petursson
 
Encode source with PHP htmlspecialchars() or htmlentities(), then put it into <XMP>... </XMP> block.

------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.
 
Not to be a smartass, but should'nt it be a <pre> tag?

Nobody enjoys shooting penguins, but if you have to shoot penguins, you might as well enjoy it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top