Monday, September 24, 2007

How to publish program code in blog post?

In my previous post How to add SWF files to blog posts?, I have published a code to use in the blog. You must be aware that publishing code like html, php etc is very different from publishing simple text, because the code itself get parsed by the browser, so that you don't see the actual code but only the result of what the code does. To prevent this we must instruct the blogging platform to display the code as text and not to execute it. If you are thinking that using the <code> tag will do, then you are wrong. Don't ask me why, because I'm no html expert. The trick is to replace the "<" with "&lt;" Once you do that, the code won't be executed and would be displayed as text. In some cases you might have to replace ">" , "/" and quotation (") marks too. If only replacing "<" doesn't work then try replacing the others. Here is what you have to replace.

< with &lt;

> with &gt;

" with &quot;

/ with &#47;

Read more about it in Blog Herald.


Post a Comment

Popular Posts