Replace All String But Not An Especially Tag

Replace All String But Not An Especially Tag

Hi,
I have a div tag which I can write some thing in it and if I write some thing which contains a tag it will save in my database and after load it will run, but I don't wanna run some tags, so I know have to replace < > with &lt; and &gt; but not an img tag which its class name is MyImg cause this tag inserted by my code.

its kinda security for my website because perhaps someone write refresh html tag and after load from database that tag will refresh my website.