Reply
Display code
Old 10-08-2006, 02:19 PM Display code
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
I want to make tutorials and how tos for HTML and CSS but I can't figure out how to display the code. I have tried the following tags:

Code:
<pre>
<textarea>
<code>
None of them work, the code that I am trying to display is still being rendered. What is wrong all of those tags should work.
lunchbox170 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
     
Old 10-08-2006, 03:33 PM Re: Display code
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
you have to do the opposite of this. http://www.webmaster-talk.com/asp-fo...sp-decode.html
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-08-2006, 05:43 PM Re: Display code
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
That, is not what I am talking about. I want to be able to display code, so readers see the code like you can see this

Code:
<a href="text.html">test</a>

<h1>Blah</h1>
I want my readers to see the actually html code. But I can't figure out how.
lunchbox170 is offline
Reply With Quote
View Public Profile
 
Old 10-08-2006, 05:48 PM Re: Display code
vangogh's Avatar
Post Impressionist

Posts: 8,441
Name: Steven Bradley
Location: Boulder, Colorado
You can use the <code></code> tag. You may also need to use &lt; and &gt; for the angle brackets. You may also find using <pre></pre> helpful to keep your formatting.
__________________
l Search Engine Friendly Web Design | Van SEO Design
l Tips On Marketing, SEO, Design, and Development | TheVanBlog
l Custom WordPress Themes
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 10-08-2006, 05:57 PM Re: Display code
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
Quote:
Originally Posted by lunchbox170
That, is not what I am talking about
Actually it is, which is why I said you need to do the opposite

The other thread is asking how to change the < and > back from &lt; & &gt;


so <h1>Blah</h1> is coded as &lt;h1&gt;Blah&lt;/h1&gt;
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-08-2006, 06:30 PM Re: Display code
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
Oh, you are right, that does work. sorry about that. So there is no easier way, it is a pain to type that.

Thanks
lunchbox170 is offline
Reply With Quote
View Public Profile
 
Old 10-08-2006, 06:59 PM Re: Display code
beta's Avatar
Extreme Talker

Posts: 158
Location: Outside the car looking in at the keys
sure there is... using <code></code> and <pre></pre> as said...
beta is offline
Reply With Quote
View Public Profile
 
Old 10-08-2006, 08:23 PM Re: Display code
LadynRed's Avatar
Super Moderator

Posts: 6,072
Location: Tennessee
Why do you want to make yet another html 'how to' site ? There are thousands of them out there already !
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!
"Using or working with IE is like having to wear a 1970's polyester suit with pantyhose and a girdle, to work everyday"
Carolina Corvette Club
LadynRed is offline
Reply With Quote
View Public Profile
 
Old 10-08-2006, 08:23 PM Re: Display code
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
As said, Tried it did not work, it should work, but it doesn't.
lunchbox170 is offline
Reply With Quote
View Public Profile
 
Old 10-12-2006, 02:55 AM Re: Display code
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
Quote:
=lunchbox170]So there is no easier way, it is a pain to type that.
Yep there is.
You code a server side function to parse the sections of source code when you need to do the replace.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-12-2006, 07:45 PM Re: Display code
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
That's not easier
lunchbox170 is offline
Reply With Quote
View Public Profile
 
Old 10-13-2006, 09:53 AM Re: Display code
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
it's definitely simpler, write one function, use it wherever it's required.

This one is in ASP VbScript
Code:
function toCode(strItem)
	dim i
'Change code delimiters to HTML entities
	strItem = Replace(strItem,"<","&lt;")
	strItem = Replace(strItem,">","&gt;")
	strItem = Replace(strItem,"%","%")
	strItem = replace(strItem,chr(34),"&quot;")
toCode = strItem	
end function
Use would be
Code:
 response.write tocode("<h1>Blah</h1>")
PHP would be
PHP Code:
function toCode($strItem) {
           
$html = array("<",">",chr(34));
           
$entities = array("&lt;","&gt;","&quot;");
           
$strItem str_replace($html$entities$strItem);
return 
$strItem;

Use would be
PHP Code:
echo toCode('<h1>Blah</h1>'); 
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-13-2006, 10:34 PM Re: Display code
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
no, that really isn't eaier. You have to remember not everyone knows every thing you do.

What I want to know is why code and pre tag don't work?
lunchbox170 is offline
Reply With Quote
View Public Profile
 
Old 10-14-2006, 04:19 AM Re: Display code
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
Quote:
What I want to know is why code and pre tag don't work
It's really quite simple.
HTML is a markup language NOT a scripting language.

That is to say it can only change the way the text will look on the page not how the text is sent to the user agent.

Quote:
You have to remember not everyone knows every thing you do
Yep, which is why I am pointing you to ways you can achieve what you want because HTML alone cannot.

Here is a javascript function to convert the < & > inside a <pre> element to the HTML entities.

Code:
<script type="text/javascript">
function toCode() {
	html = new Array(/</g,/>/g); 
	entities = new Array('&lt;','&gt;'); 
var codeSect = document.getElementsByTagName('pre');
for (var i=0;i<codeSect.length;i++) {
	for (var j=0;j<html.length;j++) {
		codeSect[i].innerHTML = codeSect[i].innerHTML.replace(html[j],entities[j]);
	}

}

}
</script>
Put the function code inside the <head> or in a linked .js file and use <body onLoad="toCode()"> in the document to run the code.
Bear in mind that some UAs do not execute javascript so will see the formatted element rather than the underlying code.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-14-2006, 11:21 AM Re: Display code
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
That didn't work...

It is weird pre and code tag should work, also your thing should have worked, why don't they.
lunchbox170 is offline
Reply With Quote
View Public Profile
 
Old 10-14-2006, 02:02 PM Re: Display code
chrishirst's Avatar
Super Moderator

Posts: 11,899
Location: Blackpool. UK
Quote:
why don't they.
No idea, do we get a URL to look at?


page on a test site my dev server http://ma.cands.dnsalias.com/display.asp
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-14-2006, 05:42 PM Re: Display code
lunchbox170's Avatar
Extreme Talker

Posts: 151
Name: Ben
http://www.thelnews.com

I don't have any code to display right now, and I got rid of the Javascript.
lunchbox170 is offline
Reply With Quote
View Public Profile