Ideally, you should never expose code to the end user, but I can understand that there's a situation where you might need to.
You don't have to replace >'s just <'s because they START tags, you just need to replace it with: <
Don't use a text box for that though*, just use a pre-formatted block (<pre />), and put the text inside, if you want the scroll bars, add a class (like <pre class="code" />) and add something to your stylesheet, like:
.code {
overflow: scroll;
}
* The reason not to use a text box is because Text boxes NEED to be in forms, unless they're the ROOT element in the document. There's no guarantee that your document will display right if it breaks an HTML rule like that. Text boxes are for users to type text into, not the programmer.
Hope this helps, email me if you need anything =)