I am building a blog engine for practice. The design is supposed to be fairly simple I guess..Here is how i want it to work:
As you can see, I will have to insert each of my blog entry into the database table and the content inserted should be in the form of HTML markup (since some parts of the post probably needs to be styled using CSS and thus needs some class/id identifier). Now In the case where I want to put some code snippet on my blog, isn't it going to be such a hassle? is there any workaround using some other technology i did not mention?
any comments/suggestions would be appreciated. thx.
First of all you should make sure to properly sanitise your data when passing it to the database.
When you want to display code, just put everything in a pre-block (just like you would here on SO)
<pre>
/* your code */
</pre>
This way your post will be displayed with all the spaces, newlines, as it was passed to you originally.
On the other hand you still have to make sure to escape certain characters: eg. instead of <, > or & you should put <, > and &
If you want your code to look good, then check out google-code-prettify (some extra js & CSS and your code will look aweseome!)