Actually, in this case, it's just a matter of the fact that certain characters have special meaning in HTML. <, >, ", and so on; which is why [man]htmlspecialchars[/man] was invented. Use that when you go to write the string into the HTML page.
Or, as bradgrafelman recommends, keep it in a session so that there's no risk of it being accidentally damaged or deliberately manipulated in the first place.