I have a string in my code as per the following example:
\'; ?>
You need to use HTML characters to avoid it being turned into HTML.
so:
echo htmlspecialchars("");