Edit: Sorry, my previous answer would be for vb4. You're right of course, a vb3 template is in a double quoted string so I think you'd want to escape double quotes, and also escape the dollar sign if you don't want them to be able to insert variables. Also, if you don't escape backslashes they will be able to insert characters using sequences like \n for newline, and if they want a literal backslash they'd need to use \\. I'm guessing that's not what you'd want for inserting html but you might want it for javascript, so I think you just have to make a choice of whether or not to escape backslashes.
You can use
addcslashes() to list the characters you want to escape, so I think you'd want either $replace = addcslashes($optioncode, '"$\\'); or $replace = addcslashes($optioncode, '"$");
Escaping double quotes avoids a problem where they could insert arbitrary php code, but I don't see any risk with SQL injections because you're not using the text in a query.
ETA: Now that I think about it more I think you *would* want to include backslash in the escaped characters, because even if you want to use a \n (for example) in a javascript string, you'd want to include a literal backslash and not have php interpret the \n.