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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert a html example

Status
Not open for further replies.

Sanuye

Programmer
Apr 7, 2007
6
RO
hi all :) i've just subscribed to this forum, and i have a question: how can i insert an example of a html code into my xhtml? how about a javascript example? thanks alot :) [I am a beginner in this :-D ]
 
you would have to convert all the HTML into special characters (< to &lt; or > to &gt;). If you are using a server side language, like PHP or .NET, you can just html encode it.

PHP: (taken from PHP.net)
Code:
<?php
$str = "A 'quote' is <b>bold</b>";

// Outputs: A 'quote' is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str);

// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;
echo htmlentities($str, ENT_QUOTES);
?>

Or in .NET: (taken from MSDN)
Code:
String TestString = "This is a <Test String>.";
String EncodedString = Server.HtmlEncode(TestString);

Ron Wheeler
 
So I found a much simpler way. For some reason I thought I'd seen an older HTML tag that allowed this code, but that wasn't quite right. I did find kbd, del, ins, pre, and some other random useful tags. That aside, I saw (haven't tested yet), that if you do something like this...
Code:
<xml>
<a href="link.htm"> Link Me</a>
</xml>

will actually display all the HTML inside the XML. I'd be curious to see if this is W3C compliant.
 
please ignore the above post. Thats what I get for implicitly trusting a site without testing. I found the plaintext [deprecated] tag that will technically work, but then breaks other stuff. The XMP [depecrated] tag would work just as my example above, but does not pass w3c validation. The reccomended way is to use the pre tag with &lt; and &gt; for the tags.
 
this also works, but won't validate
Code:
<</>a href="link.htm">Link Me<</>/a>
 
You could use a readonly text area instead/. that way the html does not get interpreted. but can't be edited.
Code:
<textarea readonly>This text cannot be edited, and will not interpret html</textarea>
although I'm not sure if it validates

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
vacunita, fwiw it does nto validate:
document type does not allow element XXX here.
where XXX can be replaced with <p>, <br>, <img>, <a> (I couldn't think of anything else to try)

The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).
 
Well, I've checked and yes it gets a validation error, but its not something that is supposed to validate, its the contents of a textarea. Why it complains I don't know.

The error is referring to the <a> link nested inside the textarea, but since its part of the contents of the textarea, there is no reason for it to validate.

Its like having it inside a textbox. Its not meant to be validated, its just text that has nothing to do with the page layout or markup.

I would just ignore that particular validation error.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top