When posting code, please use [code][/code] tags.
Both code snippets you provided work as expected for me. However, as I am unsure what you mean by "doesn't work", I cannot further diagnose.
(Also, have you gone through everything in the FAQ entry posted by stahta01?)