One thing that I struggled with for ages was posting code to a blog, as the code would invariable be processed, meaning that it could not be shown. However, a bit of googling revealed that there are several online solutions which convert php or html code into blog safe code.
This one is very simple and easy to use. I used it on the previous post.
http://onlinetools.org/tools/htmlizerdata/