I have PHP configured so that magic quotes are on and register globals are off.
I do my best to always call htmlentities() for anything I am outputing that is derive
I find the best way is using a class that allows you to bind your code so you never have to worry about manually escaping your data.